Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp424003ybv; Wed, 5 Feb 2020 07:56:24 -0800 (PST) X-Google-Smtp-Source: APXvYqywyCStC7WkKQ2BqHXn+pUROc/a3EtnHL0hyhgRUUXzCufuPlQzWrEWhTyWS4nFF3WPDv3c X-Received: by 2002:a9d:7757:: with SMTP id t23mr27401725otl.315.1580918184038; Wed, 05 Feb 2020 07:56:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580918184; cv=none; d=google.com; s=arc-20160816; b=zPQRlFNaadLBWh+1RvmHpJ78gOD7KR3PTmHDtxoUWpm2dcMtTI1UyFUMh0UjYW/yFV JX+Clm/dKfYtEluXXzDjWvnNjiSJiz8Fk5fhTtecOTSZFp426kJtsQUTewYUPVoRpJ1W HXaovwe+11Qd0b7SLQ9nPyCVcijQuYL1xdVUqf4sAQNns/DdsXzAyxy7i819ItXP1Z4/ g8EVszts8Kb0L5cuCvEpcfNWUu673NHxZmbyuPxBEwpYUkMfNwr+v3hYlJfcay3KeU90 Ex3CDGi5GXz2/zzu6HQW59NqRd3asYjghb/MT6N6IP/wHcul70ut7qj4Vak5qv1WjOBw OR+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=bsdxDvHxmIPg1xvhhe9AqHP+aRx23QetwzZU7QbbYOc=; b=OREbCqAEMFPrlqVW792bkk1dw3LVaYlpmoei1vJDJJgv0oxRW2mZqF+mUVPeg8A/TE tZ//MFyOE/5XqGJ40u1blPtKB4H6vR2/1XXUzYF+BfEFnURESHXvv0KCyRZojreLpu+J UL00+mk7MgHA6IluyGXUcSh0rSeBD4BnSh9GEtPsRxXbNM3Ut3hyHttByUcks0JTWL31 zXnbAmy8QoeCRKAyJx41+uZW5q89XtGOn3n8L5Vt0yaRrPqwE212jVEgZ7nGDTOt9cRC IOkfNmKtuAAX5gmqk82iQ0TYYV7gnVttp1AWDSmkcU24eVT4jYAypI9WP1ErCEiknZtd LbzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=WDdm+HKO; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 73si214493oii.60.2020.02.05.07.56.11; Wed, 05 Feb 2020 07:56:24 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=WDdm+HKO; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727532AbgBEPzC (ORCPT + 99 others); Wed, 5 Feb 2020 10:55:02 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:41225 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbgBEPzB (ORCPT ); Wed, 5 Feb 2020 10:55:01 -0500 Received: by mail-pf1-f196.google.com with SMTP id j9so1406621pfa.8 for ; Wed, 05 Feb 2020 07:55:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=bsdxDvHxmIPg1xvhhe9AqHP+aRx23QetwzZU7QbbYOc=; b=WDdm+HKOpEsEIQS0RWC3nhmjlhtk/FeT1aUfHH09au7ka4MQr02FaB+S5Ip2wC4yWI tPqlkz3MbIqqJp5zFGOANULGu3Sn7/dWty0OEXVcYYZ1u2sCOGVE6/NdrS3NNhOyoP+C GCyWJ6GO9lBvkHFEtkgsBmdYeJe827W4M/eT6FTSoMQk4bLLDbGm1RlSjFwcB2Y/8n9a F55OcvkCGx/nHeUUgv/zWTAtucDX/WWALsfvc8qvq0Lk4QGh1a13op3hg5otgL1InjNW kFEb7iKj5JPJva3oLX//URmkf7MZS6F/MlJ2Ch9riQK6R4177pbGKkqnLC0otJ3Uh6av rI1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=bsdxDvHxmIPg1xvhhe9AqHP+aRx23QetwzZU7QbbYOc=; b=nByv621ta0/ZXMBQ9kLQgBgNB2dVzeKvr8Dc9beYh/FsgKZLvnFwvCKnGiZlBn+YAB hmZrr/j69vbJbHPSU0Xm8CWjg4sgrXnSYPUR/EP3F0q2qDteLNZWi5lkb1bdMr9zLKgM uezkcZhAslRLF/UKzpjlIz9dsjyFUStrVy0bj0ga5DSjt7c/m6tGsVKNTkKBvhD0oefc Lz7mfm5SEgwW4UMXZqYFpFgX9DaeuWct7ou9QTPEVH57kWhhywf2D1bChKHynPkYabk/ sxdC1TGOjY29YMeKtLFABhs9N0AL0t9pcPFbE5SFtWQvOyJ36YEz7aioY/5bMiODTpsY qddg== X-Gm-Message-State: APjAAAXcoXGbDly8AakqgcvtRoZE/hoPIMK3fBOWGGPqGayf5C2ZdtK4 /QcXX+s4vW24mZKKd6T0a3I= X-Received: by 2002:aa7:9816:: with SMTP id e22mr37938712pfl.229.1580918100653; Wed, 05 Feb 2020 07:55:00 -0800 (PST) Received: from emb-wallaby.amd.com ([165.204.156.251]) by smtp.gmail.com with ESMTPSA id z10sm195678pgz.88.2020.02.05.07.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 07:55:00 -0800 (PST) From: Arindam Nath To: Shyam Sundar S K , Jon Mason , Dave Jiang , Allen Hubbe , Jiasen Lin , Sanjay R Mehta Cc: linux-ntb@googlegroups.com, linux-kernel@vger.kernel.org, Arindam Nath Subject: [PATCH 04/15] NTB: define a new function to get link status Date: Wed, 5 Feb 2020 21:24:21 +0530 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since getting the status of link is a logically separate operation, we simply create a new function which will store the link status to be used later. Signed-off-by: Arindam Nath --- drivers/ntb/hw/amd/ntb_hw_amd.c | 93 ++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/drivers/ntb/hw/amd/ntb_hw_amd.c b/drivers/ntb/hw/amd/ntb_hw_amd.c index 111f33ff2bd7..f50537e0917b 100644 --- a/drivers/ntb/hw/amd/ntb_hw_amd.c +++ b/drivers/ntb/hw/amd/ntb_hw_amd.c @@ -195,6 +195,54 @@ static int amd_ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int idx, return 0; } +static int amd_ntb_get_link_status(struct amd_ntb_dev *ndev) +{ + struct pci_dev *pdev = NULL; + struct pci_dev *pci_swds = NULL; + struct pci_dev *pci_swus = NULL; + u32 stat; + int rc; + + if (ndev->ntb.topo == NTB_TOPO_SEC) { + /* Locate the pointer to Downstream Switch for this device */ + pci_swds = pci_upstream_bridge(ndev->ntb.pdev); + if (pci_swds) { + /* + * Locate the pointer to Upstream Switch for + * the Downstream Switch. + */ + pci_swus = pci_upstream_bridge(pci_swds); + if (pci_swus) { + rc = pcie_capability_read_dword(pci_swus, + PCI_EXP_LNKCTL, + &stat); + if (rc) + return 0; + } else { + return 0; + } + } else { + return 0; + } + } else if (ndev->ntb.topo == NTB_TOPO_PRI) { + /* + * For NTB primary, we simply read the Link Status and control + * register of the NTB device itself. + */ + pdev = ndev->ntb.pdev; + rc = pcie_capability_read_dword(pdev, PCI_EXP_LNKCTL, &stat); + if (rc) + return 0; + } else { + /* Catch all for everything else */ + return 0; + } + + ndev->lnk_sta = stat; + + return 1; +} + static int amd_link_is_up(struct amd_ntb_dev *ndev) { if (!ndev->peer_sta) @@ -845,11 +893,7 @@ static inline void ndev_init_struct(struct amd_ntb_dev *ndev, static int amd_poll_link(struct amd_ntb_dev *ndev) { void __iomem *mmio = ndev->peer_mmio; - struct pci_dev *pdev = NULL; - struct pci_dev *pci_swds = NULL; - struct pci_dev *pci_swus = NULL; - u32 reg, stat; - int rc; + u32 reg; reg = readl(mmio + AMD_SIDEINFO_OFFSET); reg &= NTB_LIN_STA_ACTIVE_BIT; @@ -861,44 +905,7 @@ static int amd_poll_link(struct amd_ntb_dev *ndev) ndev->cntl_sta = reg; - if (ndev->ntb.topo == NTB_TOPO_SEC) { - /* Locate the pointer to Downstream Switch for this device */ - pci_swds = pci_upstream_bridge(ndev->ntb.pdev); - if (pci_swds) { - /* - * Locate the pointer to Upstream Switch for - * the Downstream Switch. - */ - pci_swus = pci_upstream_bridge(pci_swds); - if (pci_swus) { - rc = pcie_capability_read_dword(pci_swus, - PCI_EXP_LNKCTL, - &stat); - if (rc) - return 0; - } else { - return 0; - } - } else { - return 0; - } - } else if (ndev->ntb.topo == NTB_TOPO_PRI) { - /* - * For NTB primary, we simply read the Link Status and control - * register of the NTB device itself. - */ - pdev = ndev->ntb.pdev; - rc = pcie_capability_read_dword(pdev, PCI_EXP_LNKCTL, &stat); - if (rc) - return 0; - } else { - /* Catch all for everything else */ - return 0; - } - - ndev->lnk_sta = stat; - - return 1; + return amd_ntb_get_link_status(ndev); } static void amd_link_hb(struct work_struct *work) -- 2.17.1