All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Wenpeng Liang <liangwenpeng@huawei.com>
Cc: jgg@nvidia.com, linux-rdma@vger.kernel.org, linuxarm@huawei.com
Subject: Re: [PATCH for-next 7/8] RDMA/hns: Refactor the alloc_srqc()
Date: Thu, 24 Feb 2022 15:35:49 +0200	[thread overview]
Message-ID: <YheJtTpU04bYtvNm@unreal> (raw)
In-Reply-To: <20220218110519.37375-8-liangwenpeng@huawei.com>

On Fri, Feb 18, 2022 at 07:05:18PM +0800, Wenpeng Liang wrote:
> From: Chengchang Tang <tangchengchang@huawei.com>
> 
> Abstract the alloc_srqc() into several parts and separate the alloc_srqn()
> from the alloc_srqc().
> 
> Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
> Signed-off-by: Wenpeng Liang <liangwenpeng@huawei.com>
> ---
>  drivers/infiniband/hw/hns/hns_roce_srq.c | 80 +++++++++++++++---------
>  1 file changed, 52 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/hns/hns_roce_srq.c b/drivers/infiniband/hw/hns/hns_roce_srq.c
> index e316276e18c2..2613889a02ef 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_srq.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_srq.c
> @@ -59,40 +59,39 @@ static void hns_roce_ib_srq_event(struct hns_roce_srq *srq,
>  	}
>  }
>  
> -static int alloc_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
> +static int alloc_srqn(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
>  {
> -	struct hns_roce_srq_table *srq_table = &hr_dev->srq_table;
>  	struct hns_roce_ida *srq_ida = &hr_dev->srq_table.srq_ida;
> -	struct ib_device *ibdev = &hr_dev->ib_dev;
> -	struct hns_roce_cmd_mailbox *mailbox;
> -	int ret;
>  	int id;
>  
>  	id = ida_alloc_range(&srq_ida->ida, srq_ida->min, srq_ida->max,
>  			     GFP_KERNEL);
>  	if (id < 0) {
> -		ibdev_err(ibdev, "failed to alloc srq(%d).\n", id);
> +		ibdev_err(&hr_dev->ib_dev, "failed to alloc srq(%d).\n", id);
>  		return -ENOMEM;
>  	}
> -	srq->srqn = (unsigned long)id;
>  
> -	ret = hns_roce_table_get(hr_dev, &srq_table->table, srq->srqn);
> -	if (ret) {
> -		ibdev_err(ibdev, "failed to get SRQC table, ret = %d.\n", ret);
> -		goto err_out;
> -	}
> +	srq->srqn = id;
>  
> -	ret = xa_err(xa_store(&srq_table->xa, srq->srqn, srq, GFP_KERNEL));
> -	if (ret) {
> -		ibdev_err(ibdev, "failed to store SRQC, ret = %d.\n", ret);
> -		goto err_put;
> -	}
> +	return 0;
> +}
> +
> +static void free_srqn(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
> +{
> +	ida_free(&hr_dev->srq_table.srq_ida.ida, (int)srq->srqn);
> +}
> +
> +static int hns_roce_create_srqc(struct hns_roce_dev *hr_dev,
> +				struct hns_roce_srq *srq)
> +{
> +	struct ib_device *ibdev = &hr_dev->ib_dev;
> +	struct hns_roce_cmd_mailbox *mailbox;
> +	int ret;
>  
>  	mailbox = hns_roce_alloc_cmd_mailbox(hr_dev);
>  	if (IS_ERR_OR_NULL(mailbox)) {

hns_roce_alloc_cmd_mailbox() never returns NULL, so the check should be IS_ERR()

Thanks

>  		ibdev_err(ibdev, "failed to alloc mailbox for SRQC.\n");
> -		ret = -ENOMEM;
> -		goto err_xa;
> +		return PTR_ERR(mailbox);
>  	}
>  
>  	ret = hr_dev->hw->write_srqc(srq, mailbox->buf);
> @@ -103,23 +102,42 @@ static int alloc_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
>  
>  	ret = hns_roce_create_hw_ctx(hr_dev, mailbox, HNS_ROCE_CMD_CREATE_SRQ,
>  				     srq->srqn);
> -	if (ret) {
> +	if (ret)
>  		ibdev_err(ibdev, "failed to config SRQC, ret = %d.\n", ret);
> -		goto err_mbox;
> -	}
>  
> +err_mbox:
>  	hns_roce_free_cmd_mailbox(hr_dev, mailbox);
> +	return ret;
> +}
> +
> +static int alloc_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
> +{
> +	struct hns_roce_srq_table *srq_table = &hr_dev->srq_table;
> +	struct ib_device *ibdev = &hr_dev->ib_dev;
> +	int ret;
> +
> +	ret = hns_roce_table_get(hr_dev, &srq_table->table, srq->srqn);
> +	if (ret) {
> +		ibdev_err(ibdev, "failed to get SRQC table, ret = %d.\n", ret);
> +		return ret;
> +	}
> +
> +	ret = xa_err(xa_store(&srq_table->xa, srq->srqn, srq, GFP_KERNEL));
> +	if (ret) {
> +		ibdev_err(ibdev, "failed to store SRQC, ret = %d.\n", ret);
> +		goto err_put;
> +	}
> +
> +	ret = hns_roce_create_srqc(hr_dev, srq);
> +	if (ret)
> +		goto err_xa;
>  
>  	return 0;
>  
> -err_mbox:
> -	hns_roce_free_cmd_mailbox(hr_dev, mailbox);
>  err_xa:
>  	xa_erase(&srq_table->xa, srq->srqn);
>  err_put:
>  	hns_roce_table_put(hr_dev, &srq_table->table, srq->srqn);
> -err_out:
> -	ida_free(&srq_ida->ida, id);
>  
>  	return ret;
>  }
> @@ -142,7 +160,6 @@ static void free_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
>  	wait_for_completion(&srq->free);
>  
>  	hns_roce_table_put(hr_dev, &srq_table->table, srq->srqn);
> -	ida_free(&srq_table->srq_ida.ida, (int)srq->srqn);
>  }
>  
>  static int alloc_srq_idx(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
> @@ -390,10 +407,14 @@ int hns_roce_create_srq(struct ib_srq *ib_srq,
>  	if (ret)
>  		return ret;
>  
> -	ret = alloc_srqc(hr_dev, srq);
> +	ret = alloc_srqn(hr_dev, srq);
>  	if (ret)
>  		goto err_srq_buf;
>  
> +	ret = alloc_srqc(hr_dev, srq);
> +	if (ret)
> +		goto err_srqn;
> +
>  	if (udata) {
>  		resp.srqn = srq->srqn;
>  		if (ib_copy_to_udata(udata, &resp,
> @@ -412,6 +433,8 @@ int hns_roce_create_srq(struct ib_srq *ib_srq,
>  
>  err_srqc:
>  	free_srqc(hr_dev, srq);
> +err_srqn:
> +	free_srqn(hr_dev, srq);
>  err_srq_buf:
>  	free_srq_buf(hr_dev, srq);
>  
> @@ -424,6 +447,7 @@ int hns_roce_destroy_srq(struct ib_srq *ibsrq, struct ib_udata *udata)
>  	struct hns_roce_srq *srq = to_hr_srq(ibsrq);
>  
>  	free_srqc(hr_dev, srq);
> +	free_srqn(hr_dev, srq);
>  	free_srq_buf(hr_dev, srq);
>  	return 0;
>  }
> -- 
> 2.33.0
> 

  reply	other threads:[~2022-02-24 13:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-18 11:05 [PATCH for-next 0/8] RDMA/hns: Clean up and refactor mailbox-related code Wenpeng Liang
2022-02-18 11:05 ` [PATCH for-next 1/8] RDMA/hns: Remove the unused parameter "op_modifier" in mailbox Wenpeng Liang
2022-02-24 13:30   ` Leon Romanovsky
2022-02-18 11:05 ` [PATCH for-next 2/8] RDMA/hns: Remove fixed parameter “timeout” in the mailbox Wenpeng Liang
2022-02-24 13:31   ` Leon Romanovsky
2022-02-18 11:05 ` [PATCH for-next 3/8] RDMA/hns: Remove redundant parameter "mailbox" " Wenpeng Liang
2022-02-24 13:31   ` Leon Romanovsky
2022-02-18 11:05 ` [PATCH for-next 4/8] RDMA/hns: Fix the wrong type of parameter "op" of " Wenpeng Liang
2022-02-24 13:31   ` Leon Romanovsky
2022-02-18 11:05 ` [PATCH for-next 5/8] RDMA/hns: Refactor mailbox functions Wenpeng Liang
2022-02-24 13:30   ` Leon Romanovsky
2022-02-25 10:50     ` Wenpeng Liang
2022-02-18 11:05 ` [PATCH for-next 6/8] RDMA/hns: Remove similar code that configures the hardware contexts Wenpeng Liang
2022-02-24 13:32   ` Leon Romanovsky
2022-02-18 11:05 ` [PATCH for-next 7/8] RDMA/hns: Refactor the alloc_srqc() Wenpeng Liang
2022-02-24 13:35   ` Leon Romanovsky [this message]
2022-02-25 10:53     ` Wenpeng Liang
2022-02-18 11:05 ` [PATCH for-next 8/8] RDMA/hns: Refactor the alloc_cqc() Wenpeng Liang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YheJtTpU04bYtvNm@unreal \
    --to=leon@kernel.org \
    --cc=jgg@nvidia.com \
    --cc=liangwenpeng@huawei.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.