@@ -195,6 +195,54 @@ static int amd_ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int idx,
195
195
return 0 ;
196
196
}
197
197
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
+
198
246
static int amd_link_is_up (struct amd_ntb_dev * ndev )
199
247
{
200
248
if (!ndev -> peer_sta )
@@ -845,11 +893,7 @@ static inline void ndev_init_struct(struct amd_ntb_dev *ndev,
845
893
static int amd_poll_link (struct amd_ntb_dev * ndev )
846
894
{
847
895
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 ;
853
897
854
898
reg = readl (mmio + AMD_SIDEINFO_OFFSET );
855
899
reg &= NTB_LIN_STA_ACTIVE_BIT ;
@@ -861,44 +905,7 @@ static int amd_poll_link(struct amd_ntb_dev *ndev)
861
905
862
906
ndev -> cntl_sta = reg ;
863
907
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 );
902
909
}
903
910
904
911
static void amd_link_hb (struct work_struct * work )
0 commit comments