Commit ff8d7490 authored by Juan Zhou's avatar Juan Zhou Committed by shiyongbang
Browse files

RDMA/hns: Refactor hns_roce_alloc_ucontext()

driver inclusion
category: cleanup
bugzilla: https://gitee.com/openeuler/kernel/issues/I87LTM



--------------------------------------------------------------------------

In the hns_roce_alloc_ucontext() function, the configuration
code is too much. Extract this part of the code into the function
hns_roce_get_uctx_config() to improve readability.

Signed-off-by: default avatarJuan Zhou <zhoujuan51@h-partners.com>
parent 35797503
Loading
Loading
Loading
Loading
+33 −25
Original line number Diff line number Diff line
@@ -499,6 +499,38 @@ static u32 get_udca_max_qps(struct hns_roce_dev *hr_dev,
	return qp_num;
}

static void hns_roce_get_uctx_config(struct hns_roce_dev *hr_dev,
				struct hns_roce_ucontext *context,
				struct hns_roce_ib_alloc_ucontext *ucmd,
				struct hns_roce_ib_alloc_ucontext_resp *resp)
{
	if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09)
		context->config = ucmd->config & HNS_ROCE_EXSGE_FLAGS;

	if (context->config & HNS_ROCE_EXSGE_FLAGS) {
		resp->config |= HNS_ROCE_RSP_EXSGE_FLAGS;
		resp->max_inline_data = hr_dev->caps.max_sq_inline;
	}

	if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RQ_INLINE) {
		context->config |= ucmd->config & HNS_ROCE_RQ_INLINE_FLAGS;
		if (context->config & HNS_ROCE_RQ_INLINE_FLAGS)
			resp->config |= HNS_ROCE_RSP_RQ_INLINE_FLAGS;
	}

	if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQE_INLINE) {
		context->config |= ucmd->config & HNS_ROCE_CQE_INLINE_FLAGS;
		if (context->config & HNS_ROCE_CQE_INLINE_FLAGS)
			resp->config |= HNS_ROCE_RSP_CQE_INLINE_FLAGS;
	}

	if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_DCA_MODE) {
		context->config |= ucmd->config & HNS_ROCE_UCTX_CONFIG_DCA;
		if (context->config & HNS_ROCE_UCTX_CONFIG_DCA)
			resp->config |= HNS_ROCE_UCTX_RSP_DCA_FLAGS;
	}
}

static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx,
				   struct ib_udata *udata)
{
@@ -519,31 +551,7 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx,
	if (ret)
		goto error_fail_uar_alloc;

	if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09)
		context->config = ucmd.config & HNS_ROCE_EXSGE_FLAGS;

	if (context->config & HNS_ROCE_EXSGE_FLAGS) {
		resp.config |= HNS_ROCE_RSP_EXSGE_FLAGS;
		resp.max_inline_data = hr_dev->caps.max_sq_inline;
	}

	if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RQ_INLINE) {
		context->config |= ucmd.config & HNS_ROCE_RQ_INLINE_FLAGS;
		if (context->config & HNS_ROCE_RQ_INLINE_FLAGS)
			resp.config |= HNS_ROCE_RSP_RQ_INLINE_FLAGS;
	}

	if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQE_INLINE) {
		context->config |= ucmd.config & HNS_ROCE_CQE_INLINE_FLAGS;
		if (context->config & HNS_ROCE_CQE_INLINE_FLAGS)
			resp.config |= HNS_ROCE_RSP_CQE_INLINE_FLAGS;
	}

	if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_DCA_MODE) {
		context->config |= ucmd.config & HNS_ROCE_UCTX_CONFIG_DCA;
		if (context->config & HNS_ROCE_UCTX_CONFIG_DCA)
			resp.config |= HNS_ROCE_UCTX_RSP_DCA_FLAGS;
	}
	hns_roce_get_uctx_config(hr_dev, context, &ucmd, &resp);

	ret = hns_roce_uar_alloc(hr_dev, &context->uar);
	if (ret)