From patchwork Wed Jul 12 06:00:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junxian Huang X-Patchwork-Id: 118840 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp944285vqm; Tue, 11 Jul 2023 23:29:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlHA/UDIGrLRSaQZPsNejENFVaWg2hvoE2htQIDP+Y1kTFIvteTdURQOnxsc6LX45rDaGXBi X-Received: by 2002:a17:906:15a:b0:994:1802:8391 with SMTP id 26-20020a170906015a00b0099418028391mr4046582ejh.12.1689143392931; Tue, 11 Jul 2023 23:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689143392; cv=none; d=google.com; s=arc-20160816; b=JYCf7d8D2pMFdBoj5oAOOa5YSu+faqqbVCSWBWusCPZajykvXDMFan52BHvok3PW5/ TFABjV5/dH30LMyjPDUgy6hbJ2wfwuFgxBjbZVK6ARtWvIF9je7WZp5EblVqRgQ92sKi cTx+kaUvNIyDCU26ozTSjApuqQI1Ei978534ooyNyx7/R5qkJ0G6M25iYgSa9IL0vKCG ZX/INb3jWCeE8QhtsZggbVsTAr+xEapkCtepxaEX1rAz/jwNTCYOyxefaV+22BxgJnbR 4303gp+QdJxMRmIrQ43FG/Or8rasaHTdF+OQcmy0HjJT5X3r449b6QZkyoD7q9iQ1KsA juaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=SnunlN74iaghdsahtr68JEpPV7jynV9ZABhF8PuENIQ=; fh=3H3oLXANh5v13tjHxrBYuXblpWbB01kHKe+fQJ1oJi8=; b=lfwiHtGm4ViwVwFfdE/Jpp5YC6CJYEOWCI1mxgCWAJGeWtJRdfJECqy9EevC5VTZxy Lhb5q1yMQN1ZWPi4ciGEOZx3KCcDwciSVoi+fe4Cjexct26q1Guk+naNl4jY7pkgWftg z7GJkbt9zqP6WCMxus1THA8uqYlSDxxCTrQKIvXCBV42QxIGygrTbAOkpF20+UHHGt0I H55HUAtBX2LyOqvflZPg9o8adr6fzX+RU1C+bNrg/gckyVtgGAS8LL+dwbg7Tov57OXR aRznPKNvDKJVuLLVf0Q/POKToK1BoS03NGaGKP8qnfOxHTJWDJp5LxHtZCEzKLCx36MX Iacw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b14-20020a170906490e00b00993253791d2si3808872ejq.575.2023.07.11.23.29.27; Tue, 11 Jul 2023 23:29:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231990AbjGLGDU (ORCPT + 99 others); Wed, 12 Jul 2023 02:03:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231260AbjGLGDQ (ORCPT ); Wed, 12 Jul 2023 02:03:16 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 229A810C4; Tue, 11 Jul 2023 23:03:04 -0700 (PDT) Received: from kwepemi500006.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4R16Y52ltgzPkG1; Wed, 12 Jul 2023 14:00:41 +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.27; Wed, 12 Jul 2023 14:03:00 +0800 From: Junxian Huang To: , CC: , , , Subject: [PATCH for-rc 1/3] RDMA/hns: support get xrcd num from firmware Date: Wed, 12 Jul 2023 14:00:31 +0800 Message-ID: <20230712060033.15961-2-huangjunxian6@hisilicon.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230712060033.15961-1-huangjunxian6@hisilicon.com> References: <20230712060033.15961-1-huangjunxian6@hisilicon.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500006.china.huawei.com (7.221.188.68) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771195222730587718 X-GMAIL-MSGID: 1771195222730587718 From: Luoyouming Support driver get the num of xrcd from firmware Signed-off-by: Luoyouming Signed-off-by: Junxian Huang --- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 5 ++--- drivers/infiniband/hw/hns/hns_roce_hw_v2.h | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index d4c6b9bc0a4e..fb3ce4af22b5 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -2093,9 +2093,6 @@ static void apply_func_caps(struct hns_roce_dev *hr_dev) caps->qpc_timer_hop_num = HNS_ROCE_HOP_NUM_0; caps->cqc_timer_hop_num = HNS_ROCE_HOP_NUM_0; - caps->num_xrcds = HNS_ROCE_V2_MAX_XRCD_NUM; - caps->reserved_xrcds = HNS_ROCE_V2_RSV_XRCD_NUM; - caps->num_srqwqe_segs = HNS_ROCE_V2_MAX_SRQWQE_SEGS; caps->num_idx_segs = HNS_ROCE_V2_MAX_IDX_SEGS; @@ -2218,6 +2215,7 @@ static int hns_roce_query_caps(struct hns_roce_dev *hr_dev) caps->num_cqs = 1 << hr_reg_read(resp_c, PF_CAPS_C_NUM_CQS); caps->gid_table_len[0] = hr_reg_read(resp_c, PF_CAPS_C_MAX_GID); caps->max_cqes = 1 << hr_reg_read(resp_c, PF_CAPS_C_CQ_DEPTH); + caps->num_xrcds = 1 << hr_reg_read(resp_c, PF_CAPS_C_NUM_XRCDS); caps->num_mtpts = 1 << hr_reg_read(resp_c, PF_CAPS_C_NUM_MRWS); caps->num_qps = 1 << hr_reg_read(resp_c, PF_CAPS_C_NUM_QPS); caps->max_qp_init_rdma = hr_reg_read(resp_c, PF_CAPS_C_MAX_ORD); @@ -2238,6 +2236,7 @@ static int hns_roce_query_caps(struct hns_roce_dev *hr_dev) caps->reserved_mrws = hr_reg_read(resp_e, PF_CAPS_E_RSV_MRWS); caps->chunk_sz = 1 << hr_reg_read(resp_e, PF_CAPS_E_CHUNK_SIZE_SHIFT); caps->reserved_cqs = hr_reg_read(resp_e, PF_CAPS_E_RSV_CQS); + caps->reserved_xrcds = hr_reg_read(resp_e, PF_CAPS_E_RSV_XRCDS); caps->reserved_srqs = hr_reg_read(resp_e, PF_CAPS_E_RSV_SRQS); caps->reserved_lkey = hr_reg_read(resp_e, PF_CAPS_E_RSV_LKEYS); diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.h b/drivers/infiniband/hw/hns/hns_roce_hw_v2.h index 7033eae2407c..2b87f0cf06ec 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.h +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.h @@ -42,7 +42,6 @@ #define HNS_ROCE_V2_MAX_SRQWQE_SEGS 0x1000000 #define HNS_ROCE_V2_MAX_IDX_SEGS 0x1000000 #define HNS_ROCE_V2_MAX_XRCD_NUM 0x1000000 -#define HNS_ROCE_V2_RSV_XRCD_NUM 0 #define HNS_ROCE_V2_QP_ACK_TIMEOUT_OFS_HIP08 10 @@ -1202,6 +1201,7 @@ struct hns_roce_query_pf_caps_c { #define PF_CAPS_C_NUM_CQS PF_CAPS_C_FIELD_LOC(51, 32) #define PF_CAPS_C_MAX_GID PF_CAPS_C_FIELD_LOC(60, 52) #define PF_CAPS_C_CQ_DEPTH PF_CAPS_C_FIELD_LOC(86, 64) +#define PF_CAPS_C_NUM_XRCDS PF_CAPS_C_FIELD_LOC(91, 87) #define PF_CAPS_C_NUM_MRWS PF_CAPS_C_FIELD_LOC(115, 96) #define PF_CAPS_C_NUM_QPS PF_CAPS_C_FIELD_LOC(147, 128) #define PF_CAPS_C_MAX_ORD PF_CAPS_C_FIELD_LOC(155, 148) @@ -1260,6 +1260,7 @@ struct hns_roce_query_pf_caps_e { #define PF_CAPS_E_RSV_MRWS PF_CAPS_E_FIELD_LOC(19, 0) #define PF_CAPS_E_CHUNK_SIZE_SHIFT PF_CAPS_E_FIELD_LOC(31, 20) #define PF_CAPS_E_RSV_CQS PF_CAPS_E_FIELD_LOC(51, 32) +#define PF_CAPS_E_RSV_XRCDS PF_CAPS_E_FIELD_LOC(63, 52) #define PF_CAPS_E_RSV_SRQS PF_CAPS_E_FIELD_LOC(83, 64) #define PF_CAPS_E_RSV_LKEYS PF_CAPS_E_FIELD_LOC(115, 96) From patchwork Wed Jul 12 06:00:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junxian Huang X-Patchwork-Id: 118836 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp937167vqm; Tue, 11 Jul 2023 23:09:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlHQu50clogHY7MBBc2xLKAt8AHj4GedkkFcXeeeTDuouv7fIbNdzrKHc398TrAAqfGvLmky X-Received: by 2002:a05:6830:3b04:b0:6b5:6b95:5876 with SMTP id dk4-20020a0568303b0400b006b56b955876mr18326542otb.25.1689142155277; Tue, 11 Jul 2023 23:09:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689142155; cv=none; d=google.com; s=arc-20160816; b=F9yR3mE7sszRSX1INbO8AjcELbVP41SuSwypjp+IbfMQHQXoVDVswzQk39tqdH0Ucs TOZ48Nxtj/iGdgRwSd7PcWt0E9XLLT8UDnwiT28auZ6PAv9GSlsnX/Kk1A+JdAJpAMVC lppe0VebvaKkE5dCJPprKMkai06LBI0y8FfSy3QUlQp5j04mCkYFXIqWcbFtFK2ZXeZq oknHbmbBE97ws+Pku66v1qdxOJtjAL1kXyRW7nGsdcda0aCklNM8+2alB+asUErmX7kz GsLvW1un92Cq8gBK5uP/EqOu3YZvFR1/w9telJLjzzmVzaM+BC+e5VESHIfI4lU7hl6i UgzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=6w0X/TRxUWHalXCwkESB2MIgfqHnEPY4IbIpBusJvzE=; fh=3H3oLXANh5v13tjHxrBYuXblpWbB01kHKe+fQJ1oJi8=; b=cU6944zCu24TgoHUjrBlZimOXcpgvXBuoBc2aa0qyXSRfY23YcFSbej9rb81G/NMYX UhKVu7zd9hvqBW8OavHk5J0EMpoKkTi8EEdTR7YHxg3rlrF6Cyq6rNEHUf4B7Q/IFEVm yB42ETDvkIb6IOqlTAm5/KKygPRMpZ6BSjC6FeUqvjiWI71HtKvc0+TgTrWDP6LpIyhT gQeHKx1OacJdufz32HdsKxrrDLOI1OZIEmSuQSVKBBda4d2xx17a0fa/qDQw3tX3WAVX Ean4h4q5+pE/kraAzi0m7PalYz5uj5SI01ZMoovClrg+SoaKe9hkhcwLbB/H8/Lt1yJf LcXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b5-20020a17090a6e0500b0026315d77374si10091584pjk.151.2023.07.11.23.09.02; Tue, 11 Jul 2023 23:09:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231488AbjGLGD3 (ORCPT + 99 others); Wed, 12 Jul 2023 02:03:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231981AbjGLGDR (ORCPT ); Wed, 12 Jul 2023 02:03:17 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 040B5E49; Tue, 11 Jul 2023 23:03:03 -0700 (PDT) Received: from kwepemi500006.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4R16b63k2DzrRhZ; Wed, 12 Jul 2023 14:02:26 +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.27; Wed, 12 Jul 2023 14:03:01 +0800 From: Junxian Huang To: , CC: , , , Subject: [PATCH for-rc 2/3] RDMA/hns: Remove VF extend configuration Date: Wed, 12 Jul 2023 14:00:32 +0800 Message-ID: <20230712060033.15961-3-huangjunxian6@hisilicon.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230712060033.15961-1-huangjunxian6@hisilicon.com> References: <20230712060033.15961-1-huangjunxian6@hisilicon.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500006.china.huawei.com (7.221.188.68) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771193924342002760 X-GMAIL-MSGID: 1771193924342002760 Remove VF extend configuration since the relative registers are configured in firmware currently. Signed-off-by: Junxian Huang --- drivers/infiniband/hw/hns/hns_roce_device.h | 1 - drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 84 +++------------------ drivers/infiniband/hw/hns/hns_roce_hw_v2.h | 10 --- 3 files changed, 10 insertions(+), 85 deletions(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_device.h b/drivers/infiniband/hw/hns/hns_roce_device.h index 84239b907de2..6084c1649000 100644 --- a/drivers/infiniband/hw/hns/hns_roce_device.h +++ b/drivers/infiniband/hw/hns/hns_roce_device.h @@ -714,7 +714,6 @@ struct hns_roce_caps { u32 max_rq_sg; u32 rsv0; u32 num_qps; - u32 num_pi_qps; u32 reserved_qps; u32 num_srqs; u32 max_wqes; diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index fb3ce4af22b5..c4b92d8bd98a 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -1698,29 +1698,6 @@ static int load_func_res_caps(struct hns_roce_dev *hr_dev, bool is_vf) return 0; } -static int load_ext_cfg_caps(struct hns_roce_dev *hr_dev, bool is_vf) -{ - struct hns_roce_cmq_desc desc; - struct hns_roce_cmq_req *req = (struct hns_roce_cmq_req *)desc.data; - struct hns_roce_caps *caps = &hr_dev->caps; - u32 func_num, qp_num; - int ret; - - hns_roce_cmq_setup_basic_desc(&desc, HNS_ROCE_OPC_EXT_CFG, true); - ret = hns_roce_cmq_send(hr_dev, &desc, 1); - if (ret) - return ret; - - func_num = is_vf ? 1 : max_t(u32, 1, hr_dev->func_num); - qp_num = hr_reg_read(req, EXT_CFG_QP_PI_NUM) / func_num; - caps->num_pi_qps = round_down(qp_num, HNS_ROCE_QP_BANK_NUM); - - qp_num = hr_reg_read(req, EXT_CFG_QP_NUM) / func_num; - caps->num_qps = round_down(qp_num, HNS_ROCE_QP_BANK_NUM); - - return 0; -} - static int load_pf_timer_res_caps(struct hns_roce_dev *hr_dev) { struct hns_roce_cmq_desc desc; @@ -1741,50 +1718,37 @@ static int load_pf_timer_res_caps(struct hns_roce_dev *hr_dev) return 0; } -static int query_func_resource_caps(struct hns_roce_dev *hr_dev, bool is_vf) +static int hns_roce_query_pf_resource(struct hns_roce_dev *hr_dev) { struct device *dev = hr_dev->dev; int ret; - ret = load_func_res_caps(hr_dev, is_vf); + ret = load_func_res_caps(hr_dev, false); if (ret) { - dev_err(dev, "failed to load res caps, ret = %d (%s).\n", ret, - is_vf ? "vf" : "pf"); + dev_err(dev, "failed to load pf res caps, ret = %d.\n", ret); return ret; } - if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09) { - ret = load_ext_cfg_caps(hr_dev, is_vf); - if (ret) - dev_err(dev, "failed to load ext cfg, ret = %d (%s).\n", - ret, is_vf ? "vf" : "pf"); - } + ret = load_pf_timer_res_caps(hr_dev); + if (ret) + dev_err(dev, "failed to load pf timer resource, ret = %d.\n", + ret); return ret; } -static int hns_roce_query_pf_resource(struct hns_roce_dev *hr_dev) +static int hns_roce_query_vf_resource(struct hns_roce_dev *hr_dev) { struct device *dev = hr_dev->dev; int ret; - ret = query_func_resource_caps(hr_dev, false); + ret = load_func_res_caps(hr_dev, true); if (ret) - return ret; - - ret = load_pf_timer_res_caps(hr_dev); - if (ret) - dev_err(dev, "failed to load pf timer resource, ret = %d.\n", - ret); + dev_err(dev, "failed to load vf res caps, ret = %d.\n", ret); return ret; } -static int hns_roce_query_vf_resource(struct hns_roce_dev *hr_dev) -{ - return query_func_resource_caps(hr_dev, true); -} - static int __hns_roce_set_vf_switch_param(struct hns_roce_dev *hr_dev, u32 vf_id) { @@ -1867,24 +1831,6 @@ static int config_vf_hem_resource(struct hns_roce_dev *hr_dev, int vf_id) return hns_roce_cmq_send(hr_dev, desc, 2); } -static int config_vf_ext_resource(struct hns_roce_dev *hr_dev, u32 vf_id) -{ - struct hns_roce_cmq_desc desc; - struct hns_roce_cmq_req *req = (struct hns_roce_cmq_req *)desc.data; - struct hns_roce_caps *caps = &hr_dev->caps; - - hns_roce_cmq_setup_basic_desc(&desc, HNS_ROCE_OPC_EXT_CFG, false); - - hr_reg_write(req, EXT_CFG_VF_ID, vf_id); - - hr_reg_write(req, EXT_CFG_QP_PI_NUM, caps->num_pi_qps); - hr_reg_write(req, EXT_CFG_QP_PI_IDX, vf_id * caps->num_pi_qps); - hr_reg_write(req, EXT_CFG_QP_NUM, caps->num_qps); - hr_reg_write(req, EXT_CFG_QP_IDX, vf_id * caps->num_qps); - - return hns_roce_cmq_send(hr_dev, &desc, 1); -} - static int hns_roce_alloc_vf_resource(struct hns_roce_dev *hr_dev) { u32 func_num = max_t(u32, 1, hr_dev->func_num); @@ -1899,16 +1845,6 @@ static int hns_roce_alloc_vf_resource(struct hns_roce_dev *hr_dev) vf_id, ret); return ret; } - - if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09) { - ret = config_vf_ext_resource(hr_dev, vf_id); - if (ret) { - dev_err(hr_dev->dev, - "failed to config vf-%u ext res, ret = %d.\n", - vf_id, ret); - return ret; - } - } } return 0; diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.h b/drivers/infiniband/hw/hns/hns_roce_hw_v2.h index 2b87f0cf06ec..d9693f6cc802 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.h +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.h @@ -219,7 +219,6 @@ enum hns_roce_opcode_type { HNS_ROCE_OPC_QUERY_VF_RES = 0x850e, HNS_ROCE_OPC_CFG_GMV_TBL = 0x850f, HNS_ROCE_OPC_CFG_GMV_BT = 0x8510, - HNS_ROCE_OPC_EXT_CFG = 0x8512, HNS_ROCE_QUERY_RAM_ECC = 0x8513, HNS_SWITCH_PARAMETER_CFG = 0x1033, }; @@ -956,15 +955,6 @@ struct hns_roce_func_clear { #define HNS_ROCE_V2_READ_FUNC_CLEAR_FLAG_INTERVAL 40 #define HNS_ROCE_V2_READ_FUNC_CLEAR_FLAG_FAIL_WAIT 20 -/* Fields of HNS_ROCE_OPC_EXT_CFG */ -#define EXT_CFG_VF_ID CMQ_REQ_FIELD_LOC(31, 0) -#define EXT_CFG_QP_PI_IDX CMQ_REQ_FIELD_LOC(45, 32) -#define EXT_CFG_QP_PI_NUM CMQ_REQ_FIELD_LOC(63, 48) -#define EXT_CFG_QP_NUM CMQ_REQ_FIELD_LOC(87, 64) -#define EXT_CFG_QP_IDX CMQ_REQ_FIELD_LOC(119, 96) -#define EXT_CFG_LLM_IDX CMQ_REQ_FIELD_LOC(139, 128) -#define EXT_CFG_LLM_NUM CMQ_REQ_FIELD_LOC(156, 144) - #define CFG_LLM_A_BA_L CMQ_REQ_FIELD_LOC(31, 0) #define CFG_LLM_A_BA_H CMQ_REQ_FIELD_LOC(63, 32) #define CFG_LLM_A_DEPTH CMQ_REQ_FIELD_LOC(76, 64) From patchwork Wed Jul 12 06:00:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junxian Huang X-Patchwork-Id: 118842 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp944553vqm; Tue, 11 Jul 2023 23:30:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlE2E93xLyXkhYGBROd430Q6WBR8SbYeIKLB8ZADK7bkD3XyyhTDOWoiqtQzTcdAtm7SXyZj X-Received: by 2002:a05:6512:3095:b0:4f4:b13a:d683 with SMTP id z21-20020a056512309500b004f4b13ad683mr16473348lfd.69.1689143429604; Tue, 11 Jul 2023 23:30:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689143429; cv=none; d=google.com; s=arc-20160816; b=e+Izr1m7/RkVPuOkJTZk/rcvjQ1xhmfmvFsUkQiUW7kfqUPq2gz9D2b2NJ2g9+3i4k eUrBwMIvGTuHS7e0rBeGWJ0wLCgiaXI4TgGRGN8aGpjESklFFYGK3m3tOnSK0GVyVZip 6yG2SRfG0jZGM2mYI5jkaijXoWBftxOvRWVYWm8OTeBkE1nRXHwT4uE/qzS6KY0X0Ggp FVkxYIQsePhwC4Yy3ODoz0amJmBKx8DfLuvyvGS7mbP684VM3fhDqndJC4+m8hpcr1wO /Ji7o0gv4GMpNwvFp9Zr53IaIes2jnMuL17u4ga2JI8cj/4ibuRMoeB0M7zfgiE86/OQ k7nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4QURXtVYCzVBcAVmDvbXqSK9aHBGmjBl8pLjKIivczQ=; fh=3H3oLXANh5v13tjHxrBYuXblpWbB01kHKe+fQJ1oJi8=; b=hgbs9pmrmaBofZAFLMMypnIqfizUwhPFYT8jIktSD3pn/bGReYG5vOc2lDHPJtJBax VLb/rYJ4qiyTSQ9J6AMEtBRXcBY8SwFMFbSHDtm1prdukDiCcp3s+hZVPFKE8Mt5bQdd d4lwXhWgxgeNK563FJh9RxqW/Z131xj+grlA3//AnlSS3+yeXXAdmipY/iDltDsmrRsg RocgMkjEzoUXXr3laTmI5mFGjwsX8LjSSzcbWjOe0Pkfafq8jpGUcD+KNCHtmOOTr67f 0w+OxbhNdhUXpJitJZgzaSdfAXTUhptWcjt+PhSaXj4GjYzbwwi6LxNau7F3mQa/nz+8 gRBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y17-20020aa7c251000000b0051e37b2d837si3771831edo.237.2023.07.11.23.30.06; Tue, 11 Jul 2023 23:30:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232004AbjGLGDX (ORCPT + 99 others); Wed, 12 Jul 2023 02:03:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231992AbjGLGDS (ORCPT ); Wed, 12 Jul 2023 02:03:18 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E724F1BD5; Tue, 11 Jul 2023 23:03:04 -0700 (PDT) Received: from kwepemi500006.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4R16Y6074hzPkG3; Wed, 12 Jul 2023 14:00:41 +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.27; Wed, 12 Jul 2023 14:03:01 +0800 From: Junxian Huang To: , CC: , , , Subject: [PATCH for-rc 3/3] RDMA/hns: Add check and adjust for function resource values Date: Wed, 12 Jul 2023 14:00:33 +0800 Message-ID: <20230712060033.15961-4-huangjunxian6@hisilicon.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230712060033.15961-1-huangjunxian6@hisilicon.com> References: <20230712060033.15961-1-huangjunxian6@hisilicon.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500006.china.huawei.com (7.221.188.68) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771195260385539818 X-GMAIL-MSGID: 1771195260385539818 Currently, RoCE driver gets function resource values from firmware without validity check. As these resources are mostly related to memory, an invalid value may lead to serious consequence such as kernel panic. This patch adds check for these resource values and adjusts the invalid ones. Signed-off-by: Junxian Huang --- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 116 ++++++++++++++++++++- drivers/infiniband/hw/hns/hns_roce_hw_v2.h | 37 +++++++ 2 files changed, 149 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index c4b92d8bd98a..dae0e6959fa0 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -1650,6 +1650,98 @@ static int hns_roce_config_global_param(struct hns_roce_dev *hr_dev) return hns_roce_cmq_send(hr_dev, &desc, 1); } +static const struct hns_roce_bt_num { + u32 res_offset; + u32 min; + u32 max; + enum hns_roce_res_invalid_flag invalid_flag; + enum hns_roce_res_revision revision; + bool vf_support; +} bt_num_table[] = { + {RES_OFFSET_IN_CAPS(qpc_bt_num), 1, + MAX_QPC_BT_NUM, QPC_BT_NUM_INVALID_FLAG, RES_FOR_ALL, true}, + {RES_OFFSET_IN_CAPS(srqc_bt_num), 1, + MAX_SRQC_BT_NUM, SRQC_BT_NUM_INVALID_FLAG, RES_FOR_ALL, true}, + {RES_OFFSET_IN_CAPS(cqc_bt_num), 1, + MAX_CQC_BT_NUM, CQC_BT_NUM_INVALID_FLAG, RES_FOR_ALL, true}, + {RES_OFFSET_IN_CAPS(mpt_bt_num), 1, + MAX_MPT_BT_NUM, MPT_BT_NUM_INVALID_FLAG, RES_FOR_ALL, true}, + {RES_OFFSET_IN_CAPS(sl_num), 1, + MAX_SL_NUM, QID_NUM_INVALID_FLAG, RES_FOR_ALL, true}, + {RES_OFFSET_IN_CAPS(sccc_bt_num), 1, + MAX_SCCC_BT_NUM, SCCC_BT_NUM_INVALID_FLAG, RES_FOR_ALL, true}, + {RES_OFFSET_IN_CAPS(qpc_timer_bt_num), 1, + MAX_QPC_TIMER_BT_NUM, QPC_TIMER_BT_NUM_INVALID_FLAG, + RES_FOR_ALL, false}, + {RES_OFFSET_IN_CAPS(cqc_timer_bt_num), 1, + MAX_CQC_TIMER_BT_NUM, CQC_TIMER_BT_NUM_INVALID_FLAG, + RES_FOR_ALL, false}, + {RES_OFFSET_IN_CAPS(gmv_bt_num), 1, + MAX_GMV_BT_NUM, GMV_BT_NUM_INVALID_FLAG, + RES_FOR_HIP09, true}, + {RES_OFFSET_IN_CAPS(smac_bt_num), 1, + MAX_SMAC_BT_NUM, SMAC_BT_NUM_INVALID_FLAG, + RES_FOR_HIP08, true}, + {RES_OFFSET_IN_CAPS(sgid_bt_num), 1, + MAX_SGID_BT_NUM, SGID_BT_NUM_INVALID_FLAG, + RES_FOR_HIP08, true}, +}; + +static inline bool check_res_is_supported(struct hns_roce_dev *hr_dev, + struct hns_roce_bt_num *bt_num_entry) +{ + if (!bt_num_entry->vf_support && hr_dev->is_vf) + return false; + + if (bt_num_entry->revision == RES_FOR_HIP09 && + hr_dev->pci_dev->revision <= PCI_REVISION_ID_HIP08) + return false; + + if (bt_num_entry->revision == RES_FOR_HIP08 && + hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09) + return false; + + return true; +} + +static inline void adjust_eqc_bt_num(struct hns_roce_caps *caps, + u16 *invalid_flag) +{ + if (caps->eqc_bt_num < caps->num_comp_vectors + caps->num_aeq_vectors || + caps->eqc_bt_num > MAX_EQC_BT_NUM) { + caps->eqc_bt_num = caps->eqc_bt_num > MAX_EQC_BT_NUM ? + MAX_EQC_BT_NUM : caps->num_comp_vectors + + caps->num_aeq_vectors; + *invalid_flag |= 1 << EQC_BT_NUM_INVALID_FLAG; + } +} + +static u16 adjust_res_caps(struct hns_roce_dev *hr_dev) +{ + struct hns_roce_caps *caps = &hr_dev->caps; + u16 invalid_flag = 0; + u32 min, max; + u32 *res; + int i; + + for (i = 0; i < ARRAY_SIZE(bt_num_table); i++) { + if (!check_res_is_supported(hr_dev, &bt_num_table[i])) + continue; + + res = (u32 *)((void *)caps + bt_num_table[i].res_offset); + min = bt_num_table[i].min; + max = bt_num_table[i].max; + if (*res < min || *res > max) { + *res = *res < min ? min : max; + invalid_flag |= 1 << bt_num_table[i].invalid_flag; + } + } + + adjust_eqc_bt_num(caps, &invalid_flag); + + return invalid_flag; +} + static int load_func_res_caps(struct hns_roce_dev *hr_dev, bool is_vf) { struct hns_roce_cmq_desc desc[2]; @@ -1730,11 +1822,19 @@ static int hns_roce_query_pf_resource(struct hns_roce_dev *hr_dev) } ret = load_pf_timer_res_caps(hr_dev); - if (ret) + if (ret) { dev_err(dev, "failed to load pf timer resource, ret = %d.\n", ret); + return ret; + } - return ret; + ret = adjust_res_caps(hr_dev); + if (ret) + dev_warn(dev, + "invalid resource values have been adjusted, invalid_flag = 0x%x.\n", + ret); + + return 0; } static int hns_roce_query_vf_resource(struct hns_roce_dev *hr_dev) @@ -1743,10 +1843,18 @@ static int hns_roce_query_vf_resource(struct hns_roce_dev *hr_dev) int ret; ret = load_func_res_caps(hr_dev, true); - if (ret) + if (ret) { dev_err(dev, "failed to load vf res caps, ret = %d.\n", ret); + return ret; + } - return ret; + ret = adjust_res_caps(hr_dev); + if (ret) + dev_warn(dev, + "invalid resource values have been adjusted, invalid_flag = 0x%x.\n", + ret); + + return 0; } static int __hns_roce_set_vf_switch_param(struct hns_roce_dev *hr_dev, diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.h b/drivers/infiniband/hw/hns/hns_roce_hw_v2.h index d9693f6cc802..c2d46383c88c 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.h +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.h @@ -972,6 +972,43 @@ struct hns_roce_func_clear { #define CFG_GLOBAL_PARAM_1US_CYCLES CMQ_REQ_FIELD_LOC(9, 0) #define CFG_GLOBAL_PARAM_UDP_PORT CMQ_REQ_FIELD_LOC(31, 16) +enum hns_roce_res_invalid_flag { + QPC_BT_NUM_INVALID_FLAG, + SRQC_BT_NUM_INVALID_FLAG, + CQC_BT_NUM_INVALID_FLAG, + MPT_BT_NUM_INVALID_FLAG, + EQC_BT_NUM_INVALID_FLAG, + SMAC_BT_NUM_INVALID_FLAG, + SGID_BT_NUM_INVALID_FLAG, + QID_NUM_INVALID_FLAG, + SCCC_BT_NUM_INVALID_FLAG, + GMV_BT_NUM_INVALID_FLAG, + QPC_TIMER_BT_NUM_INVALID_FLAG, + CQC_TIMER_BT_NUM_INVALID_FLAG, +}; + +enum hns_roce_res_revision { + RES_FOR_HIP08, + RES_FOR_HIP09, + RES_FOR_ALL, +}; + +#define RES_OFFSET_IN_CAPS(res) \ + (offsetof(struct hns_roce_caps, res)) + +#define MAX_QPC_BT_NUM 2048 +#define MAX_SRQC_BT_NUM 512 +#define MAX_CQC_BT_NUM 512 +#define MAX_MPT_BT_NUM 512 +#define MAX_EQC_BT_NUM 512 +#define MAX_SMAC_BT_NUM 256 +#define MAX_SGID_BT_NUM 256 +#define MAX_SL_NUM 8 +#define MAX_SCCC_BT_NUM 512 +#define MAX_GMV_BT_NUM 256 +#define MAX_QPC_TIMER_BT_NUM 1728 +#define MAX_CQC_TIMER_BT_NUM 1600 + /* * Fields of HNS_ROCE_OPC_QUERY_PF_RES, HNS_ROCE_OPC_QUERY_VF_RES * and HNS_ROCE_OPC_ALLOC_VF_RES