@@ -125,6 +125,7 @@ static inline int pciehp_writel(struct controller *ctrl, int reg, u32 value)
125125/* Field definitions in Link Capabilities Register */
126126#define MAX_LNK_SPEED 0x000F
127127#define MAX_LNK_WIDTH 0x03F0
128+ #define LINK_ACTIVE_REPORTING 0x00100000
128129
129130/* Link Width Encoding */
130131#define LNK_X1 0x01
@@ -141,6 +142,7 @@ static inline int pciehp_writel(struct controller *ctrl, int reg, u32 value)
141142#define LNK_TRN_ERR 0x0400
142143#define LNK_TRN 0x0800
143144#define SLOT_CLK_CONF 0x1000
145+ #define LINK_ACTIVE 0x2000
144146
145147/* Field definitions in Slot Capabilities Register */
146148#define ATTN_BUTTN_PRSN 0x00000001
@@ -368,11 +370,52 @@ static int pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask)
368370 return retval ;
369371}
370372
373+ static inline int check_link_active (struct controller * ctrl )
374+ {
375+ u16 link_status ;
376+
377+ if (pciehp_readw (ctrl , LNKSTATUS , & link_status ))
378+ return 0 ;
379+ return !!(link_status & LINK_ACTIVE );
380+ }
381+
382+ static void pcie_wait_link_active (struct controller * ctrl )
383+ {
384+ int timeout = 1000 ;
385+
386+ if (check_link_active (ctrl ))
387+ return ;
388+ while (timeout > 0 ) {
389+ msleep (10 );
390+ timeout -= 10 ;
391+ if (check_link_active (ctrl ))
392+ return ;
393+ }
394+ ctrl_dbg (ctrl , "Data Link Layer Link Active not set in 1000 msec\n" );
395+ }
396+
371397static int hpc_check_lnk_status (struct controller * ctrl )
372398{
373399 u16 lnk_status ;
374400 int retval = 0 ;
375401
402+ /*
403+ * Data Link Layer Link Active Reporting must be capable for
404+ * hot-plug capable downstream port. But old controller might
405+ * not implement it. In this case, we wait for 1000 ms.
406+ */
407+ if (ctrl -> link_active_reporting ){
408+ /* Wait for Data Link Layer Link Active bit to be set */
409+ pcie_wait_link_active (ctrl );
410+ /*
411+ * We must wait for 100 ms after the Data Link Layer
412+ * Link Active bit reads 1b before initiating a
413+ * configuration access to the hot added device.
414+ */
415+ msleep (100 );
416+ } else
417+ msleep (1000 );
418+
376419 retval = pciehp_readw (ctrl , LNKSTATUS , & lnk_status );
377420 if (retval ) {
378421 ctrl_err (ctrl , "%s: Cannot read LNKSTATUS register\n" ,
@@ -1131,7 +1174,7 @@ static inline void dbg_ctrl(struct controller *ctrl)
11311174struct controller * pcie_init (struct pcie_device * dev )
11321175{
11331176 struct controller * ctrl ;
1134- u32 slot_cap ;
1177+ u32 slot_cap , link_cap ;
11351178 struct pci_dev * pdev = dev -> port ;
11361179
11371180 ctrl = kzalloc (sizeof (* ctrl ), GFP_KERNEL );
@@ -1173,6 +1216,16 @@ struct controller *pcie_init(struct pcie_device *dev)
11731216 !(POWER_CTRL (ctrl ) | ATTN_LED (ctrl ) | PWR_LED (ctrl ) | EMI (ctrl )))
11741217 ctrl -> no_cmd_complete = 1 ;
11751218
1219+ /* Check if Data Link Layer Link Active Reporting is implemented */
1220+ if (pciehp_readl (ctrl , LNKCAP , & link_cap )) {
1221+ ctrl_err (ctrl , "%s: Cannot read LNKCAP register\n" , __func__ );
1222+ goto abort_ctrl ;
1223+ }
1224+ if (link_cap & LINK_ACTIVE_REPORTING ) {
1225+ ctrl_dbg (ctrl , "Link Active Reporting supported\n" );
1226+ ctrl -> link_active_reporting = 1 ;
1227+ }
1228+
11761229 /* Clear all remaining event bits in Slot Status register */
11771230 if (pciehp_writew (ctrl , SLOTSTATUS , 0x1f ))
11781231 goto abort_ctrl ;
0 commit comments