From patchwork Thu Mar 15 09:02:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honggang LI X-Patchwork-Id: 10284127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A274F602BD for ; Thu, 15 Mar 2018 09:02:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98F7527F97 for ; Thu, 15 Mar 2018 09:02:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D8CF28533; Thu, 15 Mar 2018 09:02:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 589C427F97 for ; Thu, 15 Mar 2018 09:02:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751826AbeCOJC1 (ORCPT ); Thu, 15 Mar 2018 05:02:27 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38576 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751860AbeCOJCY (ORCPT ); Thu, 15 Mar 2018 05:02:24 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C51984023141; Thu, 15 Mar 2018 09:02:23 +0000 (UTC) Received: from dhcp-13-42.nay.redhat.com (unknown [10.66.128.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C8AB202322B; Thu, 15 Mar 2018 09:02:21 +0000 (UTC) From: Honggang LI To: dledford@redhat.com, jgg@ziepe.ca, linux-rdma@vger.kernel.org Cc: noaos@mellanox.com, linux-kernel@vger.kernel.org, honli@redhat.com Subject: [PATCH 2/2] IB/core: Set width to 1X for invalid active widths when port is down Date: Thu, 15 Mar 2018 17:02:14 +0800 Message-Id: <20180315090214.21706-3-honli@redhat.com> In-Reply-To: <20180315090214.21706-1-honli@redhat.com> References: <20180315090214.21706-1-honli@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 15 Mar 2018 09:02:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 15 Mar 2018 09:02:23 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'honli@redhat.com' RCPT:'' Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Honggang Li commit f1b65df5a232 ("IB/mlx5: Add support for active_width and active_speed in RoCE"). Before this patch applied, the mlx5_ib driver set default active_width and active_speed to IB_WIDTH_4X and IB_SPEED_QDR. When the RoCE port is down, the RoCE port did not negotiate the active width with remote side. The active width is zero. If run ibstat to require the port status, ibstat will panic as it read invalid width from sys file. Signed-off-by: Honggang Li --- drivers/infiniband/core/sysfs.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c index cf36ff1f0068..722e4571f4d2 100644 --- a/drivers/infiniband/core/sysfs.c +++ b/drivers/infiniband/core/sysfs.c @@ -240,6 +240,7 @@ static ssize_t rate_show(struct ib_port *p, struct port_attribute *unused, struct ib_port_attr attr; char *speed = ""; int rate; /* in deci-Gb/sec */ + int width; ssize_t ret; ret = ib_query_port(p->ibdev, p->port_num, &attr); @@ -278,13 +279,19 @@ static ssize_t rate_show(struct ib_port *p, struct port_attribute *unused, break; } - rate *= ib_width_enum_to_int(attr.active_width); - if (rate < 0) - return -EINVAL; + width = ib_width_enum_to_int(attr.active_width); + if (width < 0) { + if (attr.state != IB_PORT_ACTIVE) + width = 1; /* default to 1X for invalid widths */ + else + return -EINVAL; + } + + rate *= width; return sprintf(buf, "%d%s Gb/sec (%dX%s)\n", rate / 10, rate % 10 ? ".5" : "", - ib_width_enum_to_int(attr.active_width), speed); + width, speed); } static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused,