From patchwork Thu Feb 21 14:49:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lijun Ou X-Patchwork-Id: 10824157 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 6E3A013B5 for ; Thu, 21 Feb 2019 14:49:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E4A43117D for ; Thu, 21 Feb 2019 14:49:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 521EB311A6; Thu, 21 Feb 2019 14:49:41 +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 D9C843118A for ; Thu, 21 Feb 2019 14:49:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727594AbfBUOtj (ORCPT ); Thu, 21 Feb 2019 09:49:39 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:44918 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728569AbfBUOtj (ORCPT ); Thu, 21 Feb 2019 09:49:39 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id A76B24C2A2C5BA9A1E8C; Thu, 21 Feb 2019 22:49:33 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.408.0; Thu, 21 Feb 2019 22:49:26 +0800 From: Lijun Ou To: , CC: , , Subject: [PATCH V3 rdma-core 3/5] libhns: Package some lines for calculating qp buffer size Date: Thu, 21 Feb 2019 22:49:46 +0800 Message-ID: <1550760588-204074-4-git-send-email-oulijun@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1550760588-204074-1-git-send-email-oulijun@huawei.com> References: <1550760588-204074-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 For readability, here moves the relatived lines of calculating qp buffer size into an independent function as well as moves the relatived lines of allocating rq inline buffer space into an independent function. Signed-off-by: Lijun Ou --- V2->V3: 1. Remove the casts on the output of malloc --- providers/hns/hns_roce_u_verbs.c | 97 +++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 40 deletions(-) diff --git a/providers/hns/hns_roce_u_verbs.c b/providers/hns/hns_roce_u_verbs.c index 4c60375..3bc63ac 100644 --- a/providers/hns/hns_roce_u_verbs.c +++ b/providers/hns/hns_roce_u_verbs.c @@ -658,25 +658,41 @@ static int hns_roce_verify_qp(struct ibv_qp_init_attr *attr, return 0; } -static int hns_roce_alloc_qp_buf(struct ibv_pd *pd, struct ibv_qp_cap *cap, - enum ibv_qp_type type, struct hns_roce_qp *qp) +static int hns_roce_alloc_recv_inl_buf(struct ibv_qp_cap *cap, + struct hns_roce_qp *qp) { int i; - int page_size = to_hr_dev(pd->context->device)->page_size; - qp->sq.wrid = - (unsigned long *)malloc(qp->sq.wqe_cnt * sizeof(uint64_t)); - if (!qp->sq.wrid) + qp->rq_rinl_buf.wqe_list = calloc(1, qp->rq.wqe_cnt * + sizeof(struct hns_roce_rinl_wqe)); + if (!qp->rq_rinl_buf.wqe_list) return -1; - if (qp->rq.wqe_cnt) { - qp->rq.wrid = malloc(qp->rq.wqe_cnt * sizeof(uint64_t)); - if (!qp->rq.wrid) { - free(qp->sq.wrid); - return -1; - } + qp->rq_rinl_buf.wqe_cnt = qp->rq.wqe_cnt; + + qp->rq_rinl_buf.wqe_list[0].sg_list = calloc(1, qp->rq.wqe_cnt * + cap->max_recv_sge * sizeof(struct hns_roce_rinl_sge)); + if (!qp->rq_rinl_buf.wqe_list[0].sg_list) { + free(qp->rq_rinl_buf.wqe_list); + return -1; + } + + for (i = 0; i < qp->rq_rinl_buf.wqe_cnt; i++) { + int wqe_size = i * cap->max_recv_sge; + + qp->rq_rinl_buf.wqe_list[i].sg_list = + &(qp->rq_rinl_buf.wqe_list[0].sg_list[wqe_size]); } + return 0; +} + +static int hns_roce_calc_qp_buff_size(struct ibv_pd *pd, struct ibv_qp_cap *cap, + enum ibv_qp_type type, + struct hns_roce_qp *qp) +{ + int page_size = to_hr_dev(pd->context->device)->page_size; + if (to_hr_dev(pd->context->device)->hw_version == HNS_ROCE_HW_VER1) { for (qp->rq.wqe_shift = 4; 1 << qp->rq.wqe_shift < sizeof(struct hns_roce_rc_send_wqe); qp->rq.wqe_shift++) @@ -704,35 +720,9 @@ static int hns_roce_alloc_qp_buf(struct ibv_pd *pd, struct ibv_qp_cap *cap, else qp->sge.sge_shift = 0; - /* alloc recv inline buf*/ - qp->rq_rinl_buf.wqe_list = - (struct hns_roce_rinl_wqe *)calloc(1, qp->rq.wqe_cnt * - sizeof(struct hns_roce_rinl_wqe)); - if (!qp->rq_rinl_buf.wqe_list) { - if (qp->rq.wqe_cnt) - free(qp->rq.wrid); - free(qp->sq.wrid); + /* alloc recv inline buf */ + if (hns_roce_alloc_recv_inl_buf(cap, qp)) return -1; - } - - qp->rq_rinl_buf.wqe_cnt = qp->rq.wqe_cnt; - - qp->rq_rinl_buf.wqe_list[0].sg_list = - (struct hns_roce_rinl_sge *)calloc(1, qp->rq.wqe_cnt * - cap->max_recv_sge * sizeof(struct hns_roce_rinl_sge)); - if (!qp->rq_rinl_buf.wqe_list[0].sg_list) { - if (qp->rq.wqe_cnt) - free(qp->rq.wrid); - free(qp->sq.wrid); - free(qp->rq_rinl_buf.wqe_list); - return -1; - } - for (i = 0; i < qp->rq_rinl_buf.wqe_cnt; i++) { - int wqe_size = i * cap->max_recv_sge; - - qp->rq_rinl_buf.wqe_list[i].sg_list = - &(qp->rq_rinl_buf.wqe_list[0].sg_list[wqe_size]); - } qp->buf_size = align((qp->sq.wqe_cnt << qp->sq.wqe_shift), page_size) + @@ -755,6 +745,33 @@ static int hns_roce_alloc_qp_buf(struct ibv_pd *pd, struct ibv_qp_cap *cap, } } + return 0; +} + +static int hns_roce_alloc_qp_buf(struct ibv_pd *pd, struct ibv_qp_cap *cap, + enum ibv_qp_type type, struct hns_roce_qp *qp) +{ + int page_size = to_hr_dev(pd->context->device)->page_size; + + qp->sq.wrid = malloc(qp->sq.wqe_cnt * sizeof(uint64_t)); + if (!qp->sq.wrid) + return -1; + + if (qp->rq.wqe_cnt) { + qp->rq.wrid = malloc(qp->rq.wqe_cnt * sizeof(uint64_t)); + if (!qp->rq.wrid) { + free(qp->sq.wrid); + return -1; + } + } + + if (hns_roce_calc_qp_buff_size(pd, cap, type, qp)) { + if (qp->rq.wqe_cnt) + free(qp->rq.wrid); + free(qp->sq.wrid); + return -1; + } + if (hns_roce_alloc_buf(&qp->buf, align(qp->buf_size, page_size), to_hr_dev(pd->context->device)->page_size)) { if (qp->rq.wqe_cnt)