Skip to contentSkip to conversation

PCI: pciehp: Add check for DL_ACTIVE bit in pciehp_check_link_status()

PATCH Superseded Sanjay R Mehta 5 participants 6 messages Oct 6, 2020 – Oct 9, 2020 PCI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: pciehp: Add check for DL_ACTIVE bit in pciehp_check_link_status()

From: Sanjay R Mehta <[email protected]>

if DL_ACTIVE bit is set it means that there is no need to check PCI_EXP_LNKSTA_LT bit, as DL_ACTIVE would have set only if the link is already trained. Hence adding a check which takes care of this scenario.

---
 drivers/pci/hotplug/pciehp_hpc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/hotplug/pciehp_hpc.c +2 -1
index 53433b3..81d1348 100644
@@ -309,7 +309,8 @@ int pciehp_check_link_status(struct controller *ctrl)
 
 	pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
 	ctrl_dbg(ctrl, "%s: lnk_status = %x\n", __func__, lnk_status);
-	if ((lnk_status & PCI_EXP_LNKSTA_LT) ||
+	if (((lnk_status & PCI_EXP_LNKSTA_LT) &
+	     !(lnk_status & PCI_EXP_DPC_CAP_DL_ACTIVE)) ||
 	    !(lnk_status & PCI_EXP_LNKSTA_NLW)) {
 		ctrl_err(ctrl, "link training error: status %#06x\n",
 			 lnk_status);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 4 lines · Sanjay R Mehta

if DL_ACTIVE bit is set it means that there is no need to check PCI_EXP_LNKSTA_LT bit, as DL_ACTIVE would have set only if the link is already trained. Hence adding a check which takes care of this scenario.

Sorry for being dense but I don't understand this at all:

The PCI_EXP_DPC_CAP_DL_ACTIVE bit which you check here indicates that the port is capable of sending an ERR_COR interrupt whenever the link transitions from inactive to active.

What is the connection to the PCI_EXP_LNKSTA_LT bit (which indicates that the link is still being trained)?

Also, the negation of a bitwise AND is always either 0 or 1 (!(lnk_status & PCI_EXP_DPC_CAP_DL_ACTIVE)), so bit 0 is set or not set. However PCI_EXP_LNKSTA_LT is bit 11. A bitwise AND of bit 11 and 0 is always 0, so the expression can never be 1.

Am I missing something?

Thanks,

Lukas

Quoted 21 lines
---
 drivers/pci/hotplug/pciehp_hpc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/hotplug/pciehp_hpc.c +2 -1
index 53433b3..81d1348 100644
@@ -309,7 +309,8 @@ int pciehp_check_link_status(struct controller *ctrl)
 
 	pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
 	ctrl_dbg(ctrl, "%s: lnk_status = %x\n", __func__, lnk_status);
-	if ((lnk_status & PCI_EXP_LNKSTA_LT) ||
+	if (((lnk_status & PCI_EXP_LNKSTA_LT) &
+	     !(lnk_status & PCI_EXP_DPC_CAP_DL_ACTIVE)) ||
 	    !(lnk_status & PCI_EXP_LNKSTA_NLW)) {
 		ctrl_err(ctrl, "link training error: status %#06x\n",
 			 lnk_status);
Signature · 1 line
2.7.4
#2 lore raw
Quoted 17 lines · Lukas Wunner

[CAUTION: External Email]

Quoted 4 lines · Sanjay R Mehta

if DL_ACTIVE bit is set it means that there is no need to check PCI_EXP_LNKSTA_LT bit, as DL_ACTIVE would have set only if the link is already trained. Hence adding a check which takes care of this scenario.

Sorry for being dense but I don't understand this at all:

The PCI_EXP_DPC_CAP_DL_ACTIVE bit which you check here indicates that the port is capable of sending an ERR_COR interrupt whenever the link transitions from inactive to active.

What is the connection to the PCI_EXP_LNKSTA_LT bit (which indicates that the link is still being trained)?

Quoted 7 lines

Also, the negation of a bitwise AND is always either 0 or 1 (!(lnk_status & PCI_EXP_DPC_CAP_DL_ACTIVE)), so bit 0 is set or not set. However PCI_EXP_LNKSTA_LT is bit 11. A bitwise AND of bit 11 and 0 is always 0, so the expression can never be 1.

Am I missing something?

Please accept my sincere apologies for sending the wrong patch.

I am supposed to use PCI_EXP_LNKSTA_DLLLA bit in my patch but have used PCI_EXP_DPC_CAP_DL_ACTIVE.

The correct code should be as below,

- if ((lnk_status & PCI_EXP_LNKSTA_LT) ||
+ if (((lnk_status & PCI_EXP_LNKSTA_LT) &
+ !(lnk_status & PCI_EXP_LNKSTA_DLLLA )) ||

Is it right? please share your feedback, if I am wrong. Will send out V2 patch, once you confirm on this.

Quoted 25 lines

Thanks,

Lukas

Quoted 21 lines
---
 drivers/pci/hotplug/pciehp_hpc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/hotplug/pciehp_hpc.c +2 -2
index 53433b3..81d1348 100644
@@ -309,7 +309,8 @@ int pciehp_check_link_status(struct controller *ctrl)
 
      pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
      ctrl_dbg(ctrl, "%s: lnk_status = %x\n", __func__, lnk_status);
-     if ((lnk_status & PCI_EXP_LNKSTA_LT) ||
+     if (((lnk_status & PCI_EXP_LNKSTA_LT) &
+          !(lnk_status & PCI_EXP_DPC_CAP_DL_ACTIVE)) ||
          !(lnk_status & PCI_EXP_LNKSTA_NLW)) {
              ctrl_err(ctrl, "link training error: status %#06x\n",
                       lnk_status);
--

2.7.4

#3 lore raw
Quoted 33 lines · Sanjay R Mehta
Quoted 15 lines · Lukas Wunner
Quoted 4 lines · Sanjay R Mehta

if DL_ACTIVE bit is set it means that there is no need to check PCI_EXP_LNKSTA_LT bit, as DL_ACTIVE would have set only if the link is already trained. Hence adding a check which takes care of this scenario.

Sorry for being dense but I don't understand this at all:

The PCI_EXP_DPC_CAP_DL_ACTIVE bit which you check here indicates that the port is capable of sending an ERR_COR interrupt whenever the link transitions from inactive to active.

What is the connection to the PCI_EXP_LNKSTA_LT bit (which indicates that the link is still being trained)?

Quoted 7 lines

Also, the negation of a bitwise AND is always either 0 or 1 (!(lnk_status & PCI_EXP_DPC_CAP_DL_ACTIVE)), so bit 0 is set or not set. However PCI_EXP_LNKSTA_LT is bit 11. A bitwise AND of bit 11 and 0 is always 0, so the expression can never be 1.

Am I missing something?

Please accept my sincere apologies for sending the wrong patch.

I am supposed to use PCI_EXP_LNKSTA_DLLLA bit in my patch but have used PCI_EXP_DPC_CAP_DL_ACTIVE.

The correct code should be as below,

drivers/pci/hotplug/pciehp_hpc.c +2 -1
-     if ((lnk_status & PCI_EXP_LNKSTA_LT) ||
+     if (((lnk_status & PCI_EXP_LNKSTA_LT) &
+          !(lnk_status & PCI_EXP_LNKSTA_DLLLA )) ||
Quoted 1 line

Is it right? please share your feedback, if I am wrong. Will send out V2 patch, once you confirm on this.

At least you are ignoring LKP valid warning...

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
In reply to Sanjay R Mehta

drivers/pci/hotplug/pciehp_hpc.c int pciehp_check_link_status(struct controller *ctrl)

Quoted 10 lines · Sanjay R Mehta
Quoted 1 line · Lukas Wunner

On Tue, Oct 06, 2020 at 01:24:28PM -0500, Sanjay R Mehta wrote:

I am supposed to use PCI_EXP_LNKSTA_DLLLA bit in my patch but have used PCI_EXP_DPC_CAP_DL_ACTIVE.

The correct code should be as below,

drivers/pci/hotplug/pciehp_hpc.c +2 -1
-     if ((lnk_status & PCI_EXP_LNKSTA_LT) ||
+     if (((lnk_status & PCI_EXP_LNKSTA_LT) &
+          !(lnk_status & PCI_EXP_LNKSTA_DLLLA )) ||

So you want to ignore a set Link Training bit if the DLLLA bit is also set (i.e. the link is up). Why do you need this? Is there broken AMD hardware which fails to clear the Link Training bit when the LTSSM exits the Configuration/Recovery state?

Again, please note that you need && instead of &.

Thanks,

Lukas

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
---
 drivers/pci/hotplug/pciehp_hpc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/hotplug/pciehp_hpc.c +2 -2
index 53433b3..81d1348 100644
@@ -309,7 +309,8 @@ int pciehp_check_link_status(struct controller *ctrl)
 
      pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
      ctrl_dbg(ctrl, "%s: lnk_status = %x\n", __func__, lnk_status);
-     if ((lnk_status & PCI_EXP_LNKSTA_LT) ||
+     if (((lnk_status & PCI_EXP_LNKSTA_LT) &
+          !(lnk_status & PCI_EXP_DPC_CAP_DL_ACTIVE)) ||
          !(lnk_status & PCI_EXP_LNKSTA_NLW)) {
              ctrl_err(ctrl, "link training error: status %#06x\n",
                       lnk_status);
--

2.7.4

#5 lore raw
In reply to Sanjay R Mehta

Hi Sanjay,

url:    https://github.com/0day-ci/linux/commits/Sanjay-R-Mehta/PCI-pciehp-Add-check-for-DL_ACTIVE-bit-in-pciehp_check_link_status/20201007-022638 
base:    549738f15da0e5a00275977623be199fbbf7df50
config: x86_64-randconfig-m001-20201005 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate

smatch warnings:
drivers/pci/hotplug/pciehp_hpc.c:313 pciehp_check_link_status() warn: maybe use && instead of &

vim +313 drivers/pci/hotplug/pciehp_hpc.c

82a9e79ef132cbf Kenji Kaneshige   2009-09-15  290  int pciehp_check_link_status(struct controller *ctrl)
^1da177e4c3f415 Linus Torvalds    2005-04-16  291  {
cd84d34074f5659 Bjorn Helgaas     2013-05-09  292  	struct pci_dev *pdev = ctrl_dev(ctrl);
1a84b99ccbb954c Bjorn Helgaas     2013-12-14  293  	bool found;
^1da177e4c3f415 Linus Torvalds    2005-04-16  294  	u16 lnk_status;
^1da177e4c3f415 Linus Torvalds    2005-04-16  295  
f0157160b359b1d Keith Busch       2018-09-20  296  	if (!pcie_wait_for_link(pdev, true))
f0157160b359b1d Keith Busch       2018-09-20  297  		return -1;
f18e9625e02bb3e Kenji Kaneshige   2008-10-22  298  
f496648b99f8f7f Alexandru Gagniuc 2019-10-25  299  	if (ctrl->inband_presence_disabled)
f496648b99f8f7f Alexandru Gagniuc 2019-10-25  300  		pcie_wait_for_presence(pdev);
f496648b99f8f7f Alexandru Gagniuc 2019-10-25  301  
2f5d8e4ff947ad6 Yinghai Lu        2012-01-27  302  	found = pci_bus_check_dev(ctrl->pcie->port->subordinate,
2f5d8e4ff947ad6 Yinghai Lu        2012-01-27  303  					PCI_DEVFN(0, 0));
0027cb3e1947d0f Kenji Kaneshige   2011-11-10  304  
6c35a1ac3da63a7 Lukas Wunner      2018-07-19  305  	/* ignore link or presence changes up to this point */
6c35a1ac3da63a7 Lukas Wunner      2018-07-19  306  	if (found)
6c35a1ac3da63a7 Lukas Wunner      2018-07-19  307  		atomic_and(~(PCI_EXP_SLTSTA_DLLSC | PCI_EXP_SLTSTA_PDC),
6c35a1ac3da63a7 Lukas Wunner      2018-07-19  308  			   &ctrl->pending_events);
6c35a1ac3da63a7 Lukas Wunner      2018-07-19  309  
1a84b99ccbb954c Bjorn Helgaas     2013-12-14  310  	pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
7f2feec140f1f1e Taku Izumi        2008-09-05  311  	ctrl_dbg(ctrl, "%s: lnk_status = %x\n", __func__, lnk_status);
818dc520d6f8472 Sanjay R Mehta    2020-10-06  312  	if (((lnk_status & PCI_EXP_LNKSTA_LT) &
                                                                                              ^

This won't ever be true. PCI_EXP_LNKSTA_LT is 0x0800. It needs to be &&.

818dc520d6f8472 Sanjay R Mehta    2020-10-06 @313  	     !(lnk_status & PCI_EXP_DPC_CAP_DL_ACTIVE)) ||
322162a71bd9fc4 Kenji Kaneshige   2008-12-19  314  	    !(lnk_status & PCI_EXP_LNKSTA_NLW)) {
3784e0c6b02d4fa Bjorn Helgaas     2015-06-15  315  		ctrl_err(ctrl, "link training error: status %#06x\n",
3784e0c6b02d4fa Bjorn Helgaas     2015-06-15  316  			 lnk_status);
1a84b99ccbb954c Bjorn Helgaas     2013-12-14  317  		return -1;
^1da177e4c3f415 Linus Torvalds    2005-04-16  318  	}
^1da177e4c3f415 Linus Torvalds    2005-04-16  319  
fdbd3ce9efb3a04 Yinghai Lu        2011-11-07  320  	pcie_update_link_speed(ctrl->pcie->port->subordinate, lnk_status);
fdbd3ce9efb3a04 Yinghai Lu        2011-11-07  321  
1a84b99ccbb954c Bjorn Helgaas     2013-12-14  322  	if (!found)
1a84b99ccbb954c Bjorn Helgaas     2013-12-14  323  		return -1;
2f5d8e4ff947ad6 Yinghai Lu        2012-01-27  324  
1a84b99ccbb954c Bjorn Helgaas     2013-12-14  325  	return 0;
^1da177e4c3f415 Linus Torvalds    2005-04-16  326  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

_______________________________________________
kbuild mailing list -- kbuild(a)lists.01.org
To unsubscribe send an email to kbuild-leave(a)lists.01.org