From: Sanjay R Mehta <Sanju.Mehta@amd.com>
To: Shyam-sundar.S-k@amd.com, linjiasen@hygon.cn,
arindam.nath@amd.com, jdmason@kudzu.us, dave.jiang@intel.com,
allenbh@gmail.com
Cc: linux-ntb@googlegroups.com, linux-kernel@vger.kernel.org,
Sanjay R Mehta <sanju.mehta@amd.com>
Subject: [PATCH] NTB: Fix access to link status and control register
Date: Tue, 26 Nov 2019 09:01:16 -0600 [thread overview]
Message-ID: <1574780476-4423-1-git-send-email-Sanju.Mehta@amd.com> (raw)
From: Sanjay R Mehta <sanju.mehta@amd.com>
The design of AMD NTB implementation is such that
the NTB secondary endpoint is behind a combination
of Upstream Switch (SWUS) and a Downstream Switch
(SWDS). The link training happens on the SWUS and
not on the secondary endpoint. So to correctly
return the link status on the NTB secondary, we
need to read the link status of the SWUS.
Signed-off-by: Jiasen Lin <linjiasen@hygon.cn>
Signed-off-by: Arindam Nath <arindam.nath@amd.com>
Signed-off-by: Sanjay R Mehta <sanju.mehta@amd.com>
---
drivers/ntb/hw/amd/ntb_hw_amd.c | 45 +++++++++++++++++++++++++++++++++++++----
1 file changed, 41 insertions(+), 4 deletions(-)
diff --git a/drivers/ntb/hw/amd/ntb_hw_amd.c b/drivers/ntb/hw/amd/ntb_hw_amd.c
index ae91105..758f748 100644
--- a/drivers/ntb/hw/amd/ntb_hw_amd.c
+++ b/drivers/ntb/hw/amd/ntb_hw_amd.c
@@ -842,6 +842,9 @@ 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;
@@ -855,10 +858,44 @@ static int amd_poll_link(struct amd_ntb_dev *ndev)
ndev->cntl_sta = reg;
- rc = pcie_capability_read_dword(ndev->ntb.pdev,
- PCI_EXP_LNKCTL, &stat);
- if (rc)
- return 0;
+ 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
+ * this device
+ */
+ pci_swus = pci_upstream_bridge(pci_swds);
+ if (pci_swus) {
+ /*
+ * Read the PCIe Link Control and
+ * Status register
+ */
+ 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;
+ }
+
ndev->lnk_sta = stat;
return 1;
--
2.7.4
reply other threads:[~2019-11-26 15:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1574780476-4423-1-git-send-email-Sanju.Mehta@amd.com \
--to=sanju.mehta@amd.com \
--cc=Shyam-sundar.S-k@amd.com \
--cc=allenbh@gmail.com \
--cc=arindam.nath@amd.com \
--cc=dave.jiang@intel.com \
--cc=jdmason@kudzu.us \
--cc=linjiasen@hygon.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-ntb@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®