Link bandwidth notification fixes
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
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
@@ -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
PATCH 2/2 PCI/LINK: bw_notification: Deduplicate reports for multi-function devices
In reply to Lukas WunnerIf 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
@@ -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
@@ -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
@@ -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
Re: [PATCH 1/2] PCI/LINK: bw_notification: Clear interrupt before enabling it
In reply to Lukas WunnerQuoted 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
Signed-off-by Lukas Wunner <[email protected]>
Quoted 18 lines
--- drivers/pci/pcie/bw_notification.c | 2 ++ 1 file changed, 2 insertions(+)drivers/pci/pcie/bw_notification.c +2
-0@@ -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);
Re: [PATCH 2/2] PCI/LINK: bw_notification: Deduplicate reports for multi-function devices
In reply to Lukas WunnerQuoted 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
Signed-off-by Lukas Wunner <[email protected]>
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@@ -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@@ -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@@ -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 ;
Bjorn Helgaas
AppliedQuoted 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()topcie_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!