Skip to contentSkip to conversation

Link bandwidth notification fixes

PATCH Applied Lukas Wunner 3 participants 6 messages Mar 20, 2019 – Mar 25, 2019 PCI

lore
Share & tools
lore
#0 lore raw

cover Link bandwidth notification fixes

These two small patches fix issues that showed up on my laptop when testing the new bandwidth notification port service. It may be worth applying them to 5.1 still.

They're intended to be applied on top of Alexandru's patch "Do not leave interrupt handler NULL" (or an updated version thereof which moves the call to pcie_update_link_speed() to pcie_bw_notification_irq() per my suggestion).

Thanks,

Lukas

Lukas Wunner (2):
PCI/LINK: bw_notification: Clear interrupt before enabling it PCI/LINK: bw_notification: Deduplicate reports for multi-function
devices

 drivers/pci/pci.h                  | 1 +
 drivers/pci/pcie/bw_notification.c | 4 +++-
 drivers/pci/probe.c                | 2 +-
 3 files changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 PCI/LINK: bw_notification: Clear interrupt before enabling it

When booting a MacBookPro9,1, duplicate link downtraining messages are logged for the devices directly attached to the two CPU-internal Root Ports of the Core i7 3615QM: Once on device enumeration and once on enablement of the bandwidth notification interrupt on the Root Ports.

Duplicate messages do not occur with Root Ports on the PCH and Downstream Ports on the Thunderbolt controller: Only a single message is logged for these, namely on device enumeration.

The reason for the duplicate messages is a stale interrupt in the Link Status register of the 3615QM's internal Root Ports. Avoid by clearing the interrupt before enabling it.

An alternative approach would be to clear the interrupt already on device enumeration or to report link downtraining only if the speed has changed. That way, link downtraining occurring between device enumeration and enablement of the bandwidth notification interrupt could be catched. However clearing stale interrupts before enabling them is a standard operating procedure for any driver and keeping the two steps in one place makes the code easier to follow.

---
 drivers/pci/pcie/bw_notification.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/pcie/bw_notification.c +2 -0
index 001d6253ad48..69e6ba2558bf 100644
@@ -30,6 +30,8 @@ static void pcie_enable_link_bandwidth_notification(struct pci_dev *dev)
 {
 	u16 lnk_ctl;
 
+	pcie_capability_write_word(dev, PCI_EXP_LNKSTA, PCI_EXP_LNKSTA_LBMS);
+
 	pcie_capability_read_word(dev, PCI_EXP_LNKCTL, &lnk_ctl);
 	lnk_ctl |= PCI_EXP_LNKCTL_LBMIE;
 	pcie_capability_write_word(dev, PCI_EXP_LNKCTL, lnk_ctl);
Signature · 1 line
2.20.1
Reviewed-by Alexandru Gagniuc on v1 1/2
#2 lore raw

Re: [PATCH 1/2] PCI/LINK: bw_notification: Clear interrupt before enabling it

Quoted 24 lines · Lukas Wunner

[EXTERNAL EMAIL]

When booting a MacBookPro9,1, duplicate link downtraining messages are logged for the devices directly attached to the two CPU-internal Root Ports of the Core i7 3615QM: Once on device enumeration and once on enablement of the bandwidth notification interrupt on the Root Ports.

Duplicate messages do not occur with Root Ports on the PCH and Downstream Ports on the Thunderbolt controller: Only a single message is logged for these, namely on device enumeration.

The reason for the duplicate messages is a stale interrupt in the Link Status register of the 3615QM's internal Root Ports. Avoid by clearing the interrupt before enabling it.

An alternative approach would be to clear the interrupt already on device enumeration or to report link downtraining only if the speed has changed. That way, link downtraining occurring between device enumeration and enablement of the bandwidth notification interrupt could be catched. However clearing stale interrupts before enabling them is a standard operating procedure for any driver and keeping the two steps in one place makes the code easier to follow.

Quoted 1 line
Quoted 18 lines
---
  drivers/pci/pcie/bw_notification.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/pci/pcie/bw_notification.c +2 -0
index 001d6253ad48..69e6ba2558bf 100644
@@ -30,6 +30,8 @@ static void pcie_enable_link_bandwidth_notification(struct pci_dev *dev)
  {
  	u16 lnk_ctl;
 
+	pcie_capability_write_word(dev, PCI_EXP_LNKSTA, PCI_EXP_LNKSTA_LBMS);
+
  	pcie_capability_read_word(dev, PCI_EXP_LNKCTL, &lnk_ctl);
  	lnk_ctl |= PCI_EXP_LNKCTL_LBMIE;
  	pcie_capability_write_word(dev, PCI_EXP_LNKCTL, lnk_ctl);
#3 lore raw

PATCH 2/2 PCI/LINK: bw_notification: Deduplicate reports for multi-function devices

In reply to Lukas Wunner

If a multi-function device's bandwidth is already limited when it is enumerated, a message is logged only for function 0. By contrast, when downtraining occurs after enumeration, a message is logged for all functions. That's because the former uses pcie_report_downtraining(), whereas the latter uses __pcie_print_link_status() (which doesn't filter functions != 0). I am seeing this happen on a MacBookPro9,1 with a GPU (function 0) and an integrated HDA controller (function 1).

Avoid this incongruence by calling pcie_report_downtraining() in both cases.

---
 drivers/pci/pci.h                  | 1 +
 drivers/pci/pcie/bw_notification.c | 2 +-
 drivers/pci/probe.c                | 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)
drivers/pci/pci.h +1 -0
index 224d88634115..d994839a3e24 100644
@@ -273,6 +273,7 @@ enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev);
 u32 pcie_bandwidth_capable(struct pci_dev *dev, enum pci_bus_speed *speed,
 			   enum pcie_link_width *width);
 void __pcie_print_link_status(struct pci_dev *dev, bool verbose);
+void pcie_report_downtraining(struct pci_dev *dev);
 
 /* Single Root I/O Virtualization */
 struct pci_sriov {
drivers/pci/pcie/bw_notification.c +1 -1
index 69e6ba2558bf..c26045f2a890 100644
@@ -76,7 +76,7 @@ static irqreturn_t pcie_bw_notification_handler(int irq, void *context)
 	 */
 	down_read(&pci_bus_sem);
 	list_for_each_entry(dev, &port->subordinate->devices, bus_list)
-		__pcie_print_link_status(dev, false);
+		pcie_report_downtraining(dev);
 	up_read(&pci_bus_sem);
 
 	pcie_capability_read_word(port, PCI_EXP_LNKSTA, &link_status);
drivers/pci/probe.c +1 -1
index 2ec0df04e0dc..7e12d0163863 100644
@@ -2388,7 +2388,7 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)
 	return dev;
 }
 
-static void pcie_report_downtraining(struct pci_dev *dev)
+void pcie_report_downtraining(struct pci_dev *dev)
 {
 	if (!pci_is_pcie(dev))
 		return;
Signature · 1 line
2.20.1
Reviewed-by Alexandru Gagniuc on v1 2/2
#4 lore raw

Re: [PATCH 2/2] PCI/LINK: bw_notification: Deduplicate reports for multi-function devices

Quoted 11 lines · Lukas Wunner

[EXTERNAL EMAIL]

If a multi-function device's bandwidth is already limited when it is enumerated, a message is logged only for function 0. By contrast, when downtraining occurs after enumeration, a message is logged for all functions. That's because the former uses pcie_report_downtraining(), whereas the latter uses __pcie_print_link_status() (which doesn't filter functions != 0). I am seeing this happen on a MacBookPro9,1 with a GPU (function 0) and an integrated HDA controller (function 1).

Quoted 2 lines

Avoid this incongruence by calling pcie_report_downtraining() in both cases.

Good catch! Thank you for engineering the fixes.

Quoted 1 line
Quoted 45 lines
---
  drivers/pci/pci.h                  | 1 +
  drivers/pci/pcie/bw_notification.c | 2 +-
  drivers/pci/probe.c                | 2 +-
  3 files changed, 3 insertions(+), 2 deletions(-)
drivers/pci/pci.h +1 -0
index 224d88634115..d994839a3e24 100644
@@ -273,6 +273,7 @@ enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev);
  u32 pcie_bandwidth_capable(struct pci_dev *dev, enum pci_bus_speed *speed,
  			   enum pcie_link_width *width);
  void __pcie_print_link_status(struct pci_dev *dev, bool verbose);
+void pcie_report_downtraining(struct pci_dev *dev);
 
  /* Single Root I/O Virtualization */
  struct pci_sriov {
drivers/pci/pcie/bw_notification.c +1 -1
index 69e6ba2558bf..c26045f2a890 100644
@@ -76,7 +76,7 @@ static irqreturn_t pcie_bw_notification_handler(int irq, void *context)
  	 */
  	down_read(&pci_bus_sem);
  	list_for_each_entry(dev, &port->subordinate->devices, bus_list)
-		__pcie_print_link_status(dev, false);
+		pcie_report_downtraining(dev);
  	up_read(&pci_bus_sem);
 
  	pcie_capability_read_word(port, PCI_EXP_LNKSTA, &link_status);
drivers/pci/probe.c +1 -1
index 2ec0df04e0dc..7e12d0163863 100644
@@ -2388,7 +2388,7 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)
  	return dev;
  }
 
-static void pcie_report_downtraining(struct pci_dev *dev)
+void pcie_report_downtraining(struct pci_dev *dev)
  {
  	if (!pci_is_pcie(dev))
  		return;
#5 lore raw
In reply to Lukas Wunner
Quoted 18 lines · Lukas Wunner

These two small patches fix issues that showed up on my laptop when testing the new bandwidth notification port service. It may be worth applying them to 5.1 still.

They're intended to be applied on top of Alexandru's patch "Do not leave interrupt handler NULL" (or an updated version thereof which moves the call to pcie_update_link_speed() to pcie_bw_notification_irq() per my suggestion).

Thanks,

Lukas

Lukas Wunner (2):
PCI/LINK: bw_notification: Clear interrupt before enabling it PCI/LINK: bw_notification: Deduplicate reports for multi-function
devices

Quoted 4 lines
 drivers/pci/pci.h                  | 1 +
 drivers/pci/pcie/bw_notification.c | 4 +++-
 drivers/pci/probe.c                | 2 +-
 3 files changed, 5 insertions(+), 2 deletions(-)

Applied both with Alexandru's reviewed-by to for-linus for v5.1, since this functionality is new in v5.1, thanks!