Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp31753784rwd; Fri, 7 Jul 2023 04:05:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlHWGmPVkvGTKMeErbo7qYf99BoWj86GvUMJjjqUFw/8M53C92052+m2e/jYCEMkEWGLKAFd X-Received: by 2002:a05:6a20:7fa3:b0:12c:ed6f:c114 with SMTP id d35-20020a056a207fa300b0012ced6fc114mr5126264pzj.50.1688727904330; Fri, 07 Jul 2023 04:05:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688727904; cv=none; d=google.com; s=arc-20160816; b=JrCOhAH5skTKG5KDtaSanTC5mvtFxRsETP8AXeRwrJI++NIGBqjBgTBsaNt/ZAqO87 Z1AWwE+6xn9F2wzw2gEesIqjwxTvuzjWPZy418k7lbDTETSF20NnUsAeTRDgC1C5vgt+ 300LoDNsn6MDge0s4hWwN/J++rwMpidpATJd6HilqpjuiG2SiVLWF8UAorKQUPiej1Hs yqIeyKrr14ZZrU7IGzAGl9i42ZGLIjp4/yQDXXaznkxk10Zz+AITLy0cgwv3NKlwkKzk fVJUC7Qz7I6BHLWnXGyGK/gfXuQxUaEuBF/ecApSyQ6xHbXxWgAq6pd8oPcXnzSwc3W8 xFWw== 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 :message-id:date:subject:cc:to:from; bh=GlSRkVuP6yVNlF2JAt5Ga29SI7SVj+90Zk4e2VaESi0=; fh=3H3oLXANh5v13tjHxrBYuXblpWbB01kHKe+fQJ1oJi8=; b=WYAFJw2RIyQ80c4YUkyOHAUyHaTgBsMB5r3l4YXSd4jWWIljbVMl+CkasIuLa/DqfI 4gM6rxSmchtMswi/ZI/B5GaqEjOWLKCJ8ECqwZPgiKxIvqjRB5bHxxyjVpGmzj/bcck0 ijoZTdyCXDyAdAgLJIsMJCXr4uMR77+CBJlHoqEzaKAD1YeQTj/ZoJW/olDaK+BXKBnM 5ueNCUeWdf/Ggqq/9RyvujM+Xict79cPhxI9PX7oLEfUVEhCjNmnfzAsdTDbIUF1aZqi +Ay73RoYOgM2qjvvcBXv/rWQ2tpR1aWSQ7qMJzQuk5BTNFp1N1xiZ62qYhC5VSyWCyha Mc1A== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q8-20020a17090311c800b001a6ade4c8c2si3527311plh.142.2023.07.07.04.04.49; Fri, 07 Jul 2023 04:05:04 -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 S232285AbjGGK7L (ORCPT + 99 others); Fri, 7 Jul 2023 06:59:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232033AbjGGK7J (ORCPT ); Fri, 7 Jul 2023 06:59:09 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D83E19A5; Fri, 7 Jul 2023 03:59:01 -0700 (PDT) Received: from kwepemi500006.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Qy9P33kdlz1FDfy; Fri, 7 Jul 2023 18:58: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.27; Fri, 7 Jul 2023 18:58:59 +0800 From: Junxian Huang To: , CC: , , , Subject: [PATCH v3 for-next] RDMA/core: Get IB width and speed from netdev Date: Fri, 7 Jul 2023 18:56:34 +0800 Message-ID: <20230707105634.1921046-1-huangjunxian6@hisilicon.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500006.china.huawei.com (7.221.188.68) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 From: Haoyue Xu Previously, there was no way to query the number of lanes for a network card, so the same netdev_speed would result in a fixed pair of width and speed. As network card specifications become more diverse, such fixed mode is no longer suitable, so a method is needed to obtain the correct width and speed based on the number of lanes. This patch retrieves netdev lanes and speed from net_device and translates them to IB width and speed. Also, add a generic function to translating netdev speed to IB speed. Signed-off-by: Haoyue Xu Signed-off-by: Luoyouming Signed-off-by: Junxian Huang --- drivers/infiniband/core/verbs.c | 17 +++++++++++++++-- include/rdma/ib_verbs.h | 26 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index b99b3cc283b6..55a3ac9d01e2 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -1880,6 +1880,13 @@ int ib_modify_qp_with_udata(struct ib_qp *ib_qp, struct ib_qp_attr *attr, } EXPORT_SYMBOL(ib_modify_qp_with_udata); +static void ib_get_width_and_speed(u32 netdev_speed, u32 lanes, + u16 *speed, u8 *width) +{ + *width = ib_int_to_ib_width(lanes); + *speed = ib_eth_to_ib_speed(netdev_speed / lanes); +} + int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed, u8 *width) { int rc; @@ -1902,10 +1909,16 @@ int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed, u8 *width) if (!rc && lksettings.base.speed != (u32)SPEED_UNKNOWN) { netdev_speed = lksettings.base.speed; + if (lksettings.lanes) { + ib_get_width_and_speed(netdev_speed, lksettings.lanes, + speed, width); + return 0; + } } else { netdev_speed = SPEED_1000; - pr_warn("%s speed is unknown, defaulting to %u\n", netdev->name, - netdev_speed); + if (rc) + pr_warn("%s speed is unknown, defaulting to %u\n", + netdev->name, netdev_speed); } if (netdev_speed <= SPEED_1000) { diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 1e7774ac808f..7dc926ec7fee 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -552,6 +552,18 @@ static inline int ib_width_enum_to_int(enum ib_port_width width) } } +static inline int ib_int_to_ib_width(u32 lanes) +{ + switch (lanes) { + case 1: return IB_WIDTH_1X; + case 2: return IB_WIDTH_2X; + case 4: return IB_WIDTH_4X; + case 8: return IB_WIDTH_8X; + case 12: return IB_WIDTH_12X; + default: return IB_WIDTH_1X; + } +} + enum ib_port_speed { IB_SPEED_SDR = 1, IB_SPEED_DDR = 2, @@ -563,6 +575,20 @@ enum ib_port_speed { IB_SPEED_NDR = 128, }; +static inline int ib_eth_to_ib_speed(u32 speed) +{ + switch (speed) { + case SPEED_2500: return IB_SPEED_SDR; + case SPEED_5000: return IB_SPEED_DDR; + case SPEED_10000: return IB_SPEED_FDR10; + case SPEED_14000: return IB_SPEED_FDR; + case SPEED_25000: return IB_SPEED_EDR; + case SPEED_50000: return IB_SPEED_HDR; + case SPEED_100000: return IB_SPEED_NDR; + default: return IB_SPEED_SDR; + } +} + enum ib_stat_flag { IB_STAT_FLAG_OPTIONAL = 1 << 0, }; -- 2.30.0