Skip to content

Commit 5c6404d

Browse files
amd-anathjonmason
authored andcommitted
NTB: define a new function to get link status
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 <[email protected]> Signed-off-by: Jon Mason <[email protected]>
1 parent 8a7cede commit 5c6404d

File tree

1 file changed

+50
-43
lines changed

1 file changed

+50
-43
lines changed

drivers/ntb/hw/amd/ntb_hw_amd.c

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,54 @@ static int amd_ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int idx,
195195
return 0;
196196
}
197197

198+
static int amd_ntb_get_link_status(struct amd_ntb_dev *ndev)
199+
{
200+
struct pci_dev *pdev = NULL;
201+
struct pci_dev *pci_swds = NULL;
202+
struct pci_dev *pci_swus = NULL;
203+
u32 stat;
204+
int rc;
205+
206+
if (ndev->ntb.topo == NTB_TOPO_SEC) {
207+
/* Locate the pointer to Downstream Switch for this device */
208+
pci_swds = pci_upstream_bridge(ndev->ntb.pdev);
209+
if (pci_swds) {
210+
/*
211+
* Locate the pointer to Upstream Switch for
212+
* the Downstream Switch.
213+
*/
214+
pci_swus = pci_upstream_bridge(pci_swds);
215+
if (pci_swus) {
216+
rc = pcie_capability_read_dword(pci_swus,
217+
PCI_EXP_LNKCTL,
218+
&stat);
219+
if (rc)
220+
return 0;
221+
} else {
222+
return 0;
223+
}
224+
} else {
225+
return 0;
226+
}
227+
} else if (ndev->ntb.topo == NTB_TOPO_PRI) {
228+
/*
229+
* For NTB primary, we simply read the Link Status and control
230+
* register of the NTB device itself.
231+
*/
232+
pdev = ndev->ntb.pdev;
233+
rc = pcie_capability_read_dword(pdev, PCI_EXP_LNKCTL, &stat);
234+
if (rc)
235+
return 0;
236+
} else {
237+
/* Catch all for everything else */
238+
return 0;
239+
}
240+
241+
ndev->lnk_sta = stat;
242+
243+
return 1;
244+
}
245+
198246
static int amd_link_is_up(struct amd_ntb_dev *ndev)
199247
{
200248
if (!ndev->peer_sta)
@@ -845,11 +893,7 @@ static inline void ndev_init_struct(struct amd_ntb_dev *ndev,
845893
static int amd_poll_link(struct amd_ntb_dev *ndev)
846894
{
847895
void __iomem *mmio = ndev->peer_mmio;
848-
struct pci_dev *pdev = NULL;
849-
struct pci_dev *pci_swds = NULL;
850-
struct pci_dev *pci_swus = NULL;
851-
u32 reg, stat;
852-
int rc;
896+
u32 reg;
853897

854898
reg = readl(mmio + AMD_SIDEINFO_OFFSET);
855899
reg &= NTB_LIN_STA_ACTIVE_BIT;
@@ -861,44 +905,7 @@ static int amd_poll_link(struct amd_ntb_dev *ndev)
861905

862906
ndev->cntl_sta = reg;
863907

864-
if (ndev->ntb.topo == NTB_TOPO_SEC) {
865-
/* Locate the pointer to Downstream Switch for this device */
866-
pci_swds = pci_upstream_bridge(ndev->ntb.pdev);
867-
if (pci_swds) {
868-
/*
869-
* Locate the pointer to Upstream Switch for
870-
* the Downstream Switch.
871-
*/
872-
pci_swus = pci_upstream_bridge(pci_swds);
873-
if (pci_swus) {
874-
rc = pcie_capability_read_dword(pci_swus,
875-
PCI_EXP_LNKCTL,
876-
&stat);
877-
if (rc)
878-
return 0;
879-
} else {
880-
return 0;
881-
}
882-
} else {
883-
return 0;
884-
}
885-
} else if (ndev->ntb.topo == NTB_TOPO_PRI) {
886-
/*
887-
* For NTB primary, we simply read the Link Status and control
888-
* register of the NTB device itself.
889-
*/
890-
pdev = ndev->ntb.pdev;
891-
rc = pcie_capability_read_dword(pdev, PCI_EXP_LNKCTL, &stat);
892-
if (rc)
893-
return 0;
894-
} else {
895-
/* Catch all for everything else */
896-
return 0;
897-
}
898-
899-
ndev->lnk_sta = stat;
900-
901-
return 1;
908+
return amd_ntb_get_link_status(ndev);
902909
}
903910

904911
static void amd_link_hb(struct work_struct *work)

0 commit comments

Comments
 (0)