mirror of
https://github.com/torvalds/linux.git
synced 2024-12-06 02:52:22 +00:00
55397ce8df
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 caught. 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. Signed-off-by: Lukas Wunner <lukas@wunner.de> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Alexandru Gagniuc <alex.gagniuc@dellteam.com>
122 lines
3.3 KiB
C
122 lines
3.3 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* PCI Express Link Bandwidth Notification services driver
|
|
* Author: Alexandru Gagniuc <mr.nuke.me@gmail.com>
|
|
*
|
|
* Copyright (C) 2019, Dell Inc
|
|
*
|
|
* The PCIe Link Bandwidth Notification provides a way to notify the
|
|
* operating system when the link width or data rate changes. This
|
|
* capability is required for all root ports and downstream ports
|
|
* supporting links wider than x1 and/or multiple link speeds.
|
|
*
|
|
* This service port driver hooks into the bandwidth notification interrupt
|
|
* and warns when links become degraded in operation.
|
|
*/
|
|
|
|
#include "../pci.h"
|
|
#include "portdrv.h"
|
|
|
|
static bool pcie_link_bandwidth_notification_supported(struct pci_dev *dev)
|
|
{
|
|
int ret;
|
|
u32 lnk_cap;
|
|
|
|
ret = pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &lnk_cap);
|
|
return (ret == PCIBIOS_SUCCESSFUL) && (lnk_cap & PCI_EXP_LNKCAP_LBNC);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
static void pcie_disable_link_bandwidth_notification(struct pci_dev *dev)
|
|
{
|
|
u16 lnk_ctl;
|
|
|
|
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);
|
|
}
|
|
|
|
static irqreturn_t pcie_bw_notification_irq(int irq, void *context)
|
|
{
|
|
struct pcie_device *srv = context;
|
|
struct pci_dev *port = srv->port;
|
|
u16 link_status, events;
|
|
int ret;
|
|
|
|
ret = pcie_capability_read_word(port, PCI_EXP_LNKSTA, &link_status);
|
|
events = link_status & PCI_EXP_LNKSTA_LBMS;
|
|
|
|
if (ret != PCIBIOS_SUCCESSFUL || !events)
|
|
return IRQ_NONE;
|
|
|
|
pcie_capability_write_word(port, PCI_EXP_LNKSTA, events);
|
|
pcie_update_link_speed(port->subordinate, link_status);
|
|
return IRQ_WAKE_THREAD;
|
|
}
|
|
|
|
static irqreturn_t pcie_bw_notification_handler(int irq, void *context)
|
|
{
|
|
struct pcie_device *srv = context;
|
|
struct pci_dev *port = srv->port;
|
|
struct pci_dev *dev;
|
|
|
|
/*
|
|
* Print status from downstream devices, not this root port or
|
|
* downstream switch port.
|
|
*/
|
|
down_read(&pci_bus_sem);
|
|
list_for_each_entry(dev, &port->subordinate->devices, bus_list)
|
|
__pcie_print_link_status(dev, false);
|
|
up_read(&pci_bus_sem);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static int pcie_bandwidth_notification_probe(struct pcie_device *srv)
|
|
{
|
|
int ret;
|
|
|
|
/* Single-width or single-speed ports do not have to support this. */
|
|
if (!pcie_link_bandwidth_notification_supported(srv->port))
|
|
return -ENODEV;
|
|
|
|
ret = request_threaded_irq(srv->irq, pcie_bw_notification_irq,
|
|
pcie_bw_notification_handler,
|
|
IRQF_SHARED, "PCIe BW notif", srv);
|
|
if (ret)
|
|
return ret;
|
|
|
|
pcie_enable_link_bandwidth_notification(srv->port);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void pcie_bandwidth_notification_remove(struct pcie_device *srv)
|
|
{
|
|
pcie_disable_link_bandwidth_notification(srv->port);
|
|
free_irq(srv->irq, srv);
|
|
}
|
|
|
|
static struct pcie_port_service_driver pcie_bandwidth_notification_driver = {
|
|
.name = "pcie_bw_notification",
|
|
.port_type = PCIE_ANY_PORT,
|
|
.service = PCIE_PORT_SERVICE_BWNOTIF,
|
|
.probe = pcie_bandwidth_notification_probe,
|
|
.remove = pcie_bandwidth_notification_remove,
|
|
};
|
|
|
|
int __init pcie_bandwidth_notification_init(void)
|
|
{
|
|
return pcie_port_service_register(&pcie_bandwidth_notification_driver);
|
|
}
|