Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2773032rdd; Sat, 13 Jan 2024 01:03:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEH/C9B/pz3rX4C1esq/uGONNmCU1RAEI1Ewb2lagGrdZfmTDzqxo6AE15SsHcWGNiR5bWQ X-Received: by 2002:a05:6808:2286:b0:3bc:3134:6eb2 with SMTP id bo6-20020a056808228600b003bc31346eb2mr2925561oib.67.1705136634758; Sat, 13 Jan 2024 01:03:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705136634; cv=none; d=google.com; s=arc-20160816; b=L2SZe7vTbOzzZgAIXRMezhmHsMk4fBaCKEFy/BtsVjW9PrYp/OISwthpXC6ecgN7rS jHGKzC5SQo8DT29EjExU94MscGbGCywzV3XPPbYfIYFJd+nK4Lwqo0LMQhjp7t2s7G4J 2jgkV/co1RW9fnNAun2rFm5N7yjlFLVWk4V3+Ky+gHIozL7N9aVekgRlJ+dhfme0D7nk z1ltqE8SEVlqSXyoZ/kxjjcJlXtF6LCI/82mY66R9Yn/ZmCqfmROq5+7Y6Hy30SK046y iMniyQPAO8kuKGPksoMGO03NF46oUGHAfWVSiqLK21Xcc6FMaRGPEf4Ud3X6HsVLfUii CMjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=0I/HMoRPZlioe4ShavJETAPkz4ld/VJR6j8FZZB6Woo=; fh=KWvyQxL3Ff+3WPSMjlYu+P4255AmcMULAsFol6M1vNI=; b=aWY9Wo5h4K8N+Ifq53BXpFb422UI6t7sneK/gOjjl7pLhFn8ROB55j+NhQ29X3Ul0x D/kxgy2DzYwuvGnza8Ol2uguMWDX8nAFH7WwFatn8vMzVZwedd2SdokUJNv2g1Vjssyb FIDiMNuLUgX+cY3pjBZSfp9i6PiFibfZupJGAbqPYHQFJvZYJujsyhxqGAe7zqNMLPUp knlxQHOBJGelbF1jauMsLr1iXE3pXAP/aAaHnAlGjNMJiSL8QTK93W6/2jrqXH2lW3Ag UJ59oHkAkX5AABLqfvZTfCIlkIOmFW6hGeqIRP4cscJtt1+yVY1DP3+Ve+d8o/NAxJbs GcOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-25223-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25223-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o7-20020a17090a744700b0028cfb924bd5si7426705pjk.149.2024.01.13.01.03.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jan 2024 01:03:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25223-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-25223-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25223-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 46E9828572E for ; Sat, 13 Jan 2024 09:03:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C919539E; Sat, 13 Jan 2024 09:03:36 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B46064B; Sat, 13 Jan 2024 09:03:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=hisilicon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hisilicon.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TBsps0s1sz29k0F; Sat, 13 Jan 2024 17:01:57 +0800 (CST) Received: from kwepemi500006.china.huawei.com (unknown [7.221.188.68]) by mail.maildlp.com (Postfix) with ESMTPS id A20D81400FD; Sat, 13 Jan 2024 17:03:31 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemi500006.china.huawei.com (7.221.188.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Sat, 13 Jan 2024 17:03:31 +0800 From: Junxian Huang To: , CC: , , , Subject: [PATCH v2 for-next 5/6] RDMA/hns: Support adaptive PBL hopnum Date: Sat, 13 Jan 2024 16:59:34 +0800 Message-ID: <20240113085935.2838701-6-huangjunxian6@hisilicon.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240113085935.2838701-1-huangjunxian6@hisilicon.com> References: <20240113085935.2838701-1-huangjunxian6@hisilicon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500006.china.huawei.com (7.221.188.68) From: Chengchang Tang In the current implementation, a fixed addressing level is used for PBL. But in fact, the necessary addressing level is related to page size and the size of MR. This patch calculates the addressing level according to page size and the size of MR, and uses the addressing level to configure the PBL. Signed-off-by: Chengchang Tang Signed-off-by: Junxian Huang --- drivers/infiniband/hw/hns/hns_roce_mr.c | 57 +++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_mr.c b/drivers/infiniband/hw/hns/hns_roce_mr.c index d00b4aa7214b..9e05b57a2d67 100644 --- a/drivers/infiniband/hw/hns/hns_roce_mr.c +++ b/drivers/infiniband/hw/hns/hns_roce_mr.c @@ -112,10 +112,13 @@ static int alloc_mr_pbl(struct hns_roce_dev *hr_dev, struct hns_roce_mr *mr, err = hns_roce_mtr_create(hr_dev, &mr->pbl_mtr, &buf_attr, hr_dev->caps.pbl_ba_pg_sz + PAGE_SHIFT, udata, start); - if (err) + if (err) { ibdev_err(ibdev, "failed to alloc pbl mtr, ret = %d.\n", err); - else - mr->npages = mr->pbl_mtr.hem_cfg.buf_pg_count; + return err; + } + + mr->npages = mr->pbl_mtr.hem_cfg.buf_pg_count; + mr->pbl_hop_num = buf_attr.region[0].hopnum; return err; } @@ -943,6 +946,50 @@ static int get_best_page_shift(struct hns_roce_dev *hr_dev, return 0; } +static int get_best_hop_num(struct hns_roce_dev *hr_dev, + struct hns_roce_mtr *mtr, + struct hns_roce_buf_attr *buf_attr, + unsigned int ba_pg_shift) +{ +#define INVALID_HOPNUM -1 +#define MIN_BA_CNT 1 + size_t buf_pg_sz = 1 << buf_attr->page_shift; + struct ib_device *ibdev = &hr_dev->ib_dev; + size_t ba_pg_sz = 1 << ba_pg_shift; + int hop_num = INVALID_HOPNUM; + size_t unit = MIN_BA_CNT; + size_t ba_cnt; + int j; + + if (!buf_attr->adaptive || buf_attr->type != MTR_PBL) + return 0; + + /* Caculating the number of buf pages, each buf page need a BA */ + if (mtr->umem) + ba_cnt = ib_umem_num_dma_blocks(mtr->umem, buf_pg_sz); + else + ba_cnt = DIV_ROUND_UP(buf_attr->region[0].size, buf_pg_sz); + + for (j = 0; j <= HNS_ROCE_MAX_HOP_NUM; j++) { + if (ba_cnt <= unit) { + hop_num = j; + break; + } + /* Number of BAs can be represented at per hop */ + unit *= ba_pg_sz / BA_BYTE_LEN; + } + + if (hop_num < 0) { + ibdev_err(ibdev, + "failed to calculate a valid hopnum.\n"); + return -EINVAL; + } + + buf_attr->region[0].hopnum = hop_num; + + return 0; +} + static bool is_buf_attr_valid(struct hns_roce_dev *hr_dev, struct hns_roce_buf_attr *attr) { @@ -1116,6 +1163,10 @@ int hns_roce_mtr_create(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr, ret = get_best_page_shift(hr_dev, mtr, buf_attr); if (ret) goto err_init_buf; + + ret = get_best_hop_num(hr_dev, mtr, buf_attr, ba_page_shift); + if (ret) + goto err_init_buf; } ret = mtr_init_buf_cfg(hr_dev, mtr, buf_attr); -- 2.30.0