Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp726071ybx; Thu, 7 Nov 2019 01:41:54 -0800 (PST) X-Google-Smtp-Source: APXvYqxKRVxwP0LYn9KWSUCTQWVfmXGlaDKO4VkbtbxEKh612AaVS824smv46+rak8Y/Omzffiba X-Received: by 2002:a50:f747:: with SMTP id j7mr2430294edn.247.1573119714690; Thu, 07 Nov 2019 01:41:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573119714; cv=none; d=google.com; s=arc-20160816; b=kwvY1TH8as3S7Klkxh3UYfZKZzY6PneNo2H6pT83U2OCscJXB5kVBtNiscUnPt1o9D cPjUllganFYU7LWi9ooIH5scTaqWnqp9FNN36cafLd56rxrgIFZpQnqTdZYPUWri51kg c1vayjog+mAr7B6/GzJ+RiHI2rDMpi+f97Zz9evjmGh26GLQK3rn9W7715IdXyvkeISd BNCJzmT5ciP+Z+GG1ipOOLk+0xmt+oiAJlRCCbQUGg7p+mULAlvhz0jBBKtaE1clFn2L 0b+ezgM33Lwf12+q0cjygOb4tnAft1DHoqqIS8Efhhowu1fr2I0au7RDsC8UBrU5CBec adLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=peVo9nIHie79rfdh6OdEJL8Xohafwz4IGmN2xmyvw0w=; b=GS0ITHtZdpdgSncLfRjR7S/qIjryVSjqPP2UTqQ0HkDgD2r9CZBZ8d/oM8cRhdebL+ L94MU5Gu4AxH4XA9P/CGin5EbF96EJPRIMlOq59JmnwFRWNEmymMEEQ0oBBWuNIeis51 eZnbJey7rn9j6SDFCHIHHygj2431UhMP35e2lFzbPMTM0w3vi6iTArw6mbH7oXVXjjne EFUE+i844ca8HEyg4med4YSfMIu/ygzfU8xy9haK7nL6qGlkp5a7v0XGb+NDOGlMTxZa XzlYgK6DCgGmp7dkkFK0cBKm5YTsblNOcDXBRYX4Thargfc7xOrqUijHyznD4JQEuXF/ NRLg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hygon.cn Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h21si1030927edh.110.2019.11.07.01.41.30; Thu, 07 Nov 2019 01:41:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hygon.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733306AbfKGJjw (ORCPT + 99 others); Thu, 7 Nov 2019 04:39:52 -0500 Received: from spam01.hygon.cn ([110.188.70.11]:63390 "EHLO spam2.hygon.cn" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726734AbfKGJjw (ORCPT ); Thu, 7 Nov 2019 04:39:52 -0500 Received: from MK-FE.hygon.cn ([172.23.18.61]) by spam2.hygon.cn with ESMTP id xA79aoag094479; Thu, 7 Nov 2019 17:36:51 +0800 (GMT-8) (envelope-from linjiasen@hygon.cn) Received: from cncheex01.Hygon.cn ([172.23.18.10]) by MK-FE.hygon.cn with ESMTP id xA79aiNP024677; Thu, 7 Nov 2019 17:36:44 +0800 (GMT-8) (envelope-from linjiasen@hygon.cn) Received: from ubuntu.localdomain (172.23.18.44) by cncheex01.Hygon.cn (172.23.18.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1466.3; Thu, 7 Nov 2019 17:36:46 +0800 From: Jiasen Lin To: , , , CC: , , , Subject: [PATCH] NTB: Fix an error in get link status Date: Thu, 7 Nov 2019 01:35:36 -0800 Message-ID: <1573119336-107732-1-git-send-email-linjiasen@hygon.cn> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.23.18.44] X-ClientProxiedBy: cncheex01.Hygon.cn (172.23.18.10) To cncheex01.Hygon.cn (172.23.18.10) X-MAIL: spam2.hygon.cn xA79aoag094479 X-DNSRBL: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The offset of PCIe Capability Header for AMD and HYGON NTB is 0x64, but the macro which named "AMD_LINK_STATUS_OFFSET" is defined as 0x68. It is offset of Device Capabilities Reg rather than Link Control Reg. This code trigger an error in get link statsus: cat /sys/kernel/debug/ntb_hw_amd/0000:43:00.1/info LNK STA - 0x8fa1 Link Status - Up Link Speed - PCI-E Gen 0 Link Width - x0 This patch use pcie_capability_read_dword to get link status. After fix this issue, we can get link status accurately: cat /sys/kernel/debug/ntb_hw_amd/0000:43:00.1/info LNK STA - 0x11030042 Link Status - Up Link Speed - PCI-E Gen 3 Link Width - x16 Signed-off-by: Jiasen Lin --- drivers/ntb/hw/amd/ntb_hw_amd.c | 5 +++-- drivers/ntb/hw/amd/ntb_hw_amd.h | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/ntb/hw/amd/ntb_hw_amd.c b/drivers/ntb/hw/amd/ntb_hw_amd.c index 156c2a1..ae91105 100644 --- a/drivers/ntb/hw/amd/ntb_hw_amd.c +++ b/drivers/ntb/hw/amd/ntb_hw_amd.c @@ -855,8 +855,8 @@ static int amd_poll_link(struct amd_ntb_dev *ndev) ndev->cntl_sta = reg; - rc = pci_read_config_dword(ndev->ntb.pdev, - AMD_LINK_STATUS_OFFSET, &stat); + rc = pcie_capability_read_dword(ndev->ntb.pdev, + PCI_EXP_LNKCTL, &stat); if (rc) return 0; ndev->lnk_sta = stat; @@ -1139,6 +1139,7 @@ static const struct ntb_dev_data dev_data[] = { static const struct pci_device_id amd_ntb_pci_tbl[] = { { PCI_VDEVICE(AMD, 0x145b), (kernel_ulong_t)&dev_data[0] }, { PCI_VDEVICE(AMD, 0x148b), (kernel_ulong_t)&dev_data[1] }, + { PCI_VDEVICE(HYGON, 0x145b), (kernel_ulong_t)&dev_data[0] }, { 0, } }; MODULE_DEVICE_TABLE(pci, amd_ntb_pci_tbl); diff --git a/drivers/ntb/hw/amd/ntb_hw_amd.h b/drivers/ntb/hw/amd/ntb_hw_amd.h index 139a307..39e5d18 100644 --- a/drivers/ntb/hw/amd/ntb_hw_amd.h +++ b/drivers/ntb/hw/amd/ntb_hw_amd.h @@ -53,7 +53,6 @@ #include #define AMD_LINK_HB_TIMEOUT msecs_to_jiffies(1000) -#define AMD_LINK_STATUS_OFFSET 0x68 #define NTB_LIN_STA_ACTIVE_BIT 0x00000002 #define NTB_LNK_STA_SPEED_MASK 0x000F0000 #define NTB_LNK_STA_WIDTH_MASK 0x03F00000 -- 2.7.4