platform/kernel/linux-rpi.git
6 years agoMerge branch 'lorenzo/pci/dwc-msi'
Bjorn Helgaas [Wed, 4 Apr 2018 18:28:45 +0000 (13:28 -0500)]
Merge branch 'lorenzo/pci/dwc-msi'

* lorenzo/pci/dwc-msi:
  PCI: dwc: Expand maximum number of MSI IRQs from 32 to 256
  PCI: dwc: Remove old MSI IRQs API
  PCI: dwc: Move MSI IRQs allocation to IRQ domains hierarchical API

6 years agoMerge branch 'lorenzo/pci/dwc'
Bjorn Helgaas [Wed, 4 Apr 2018 18:28:44 +0000 (13:28 -0500)]
Merge branch 'lorenzo/pci/dwc'

* lorenzo/pci/dwc:
  PCI: histb: Add an optional regulator for PCIe port power control
  PCI: histb: Fix error path of histb_pcie_host_enable()
  PCI: qcom: Use regulator bulk api for apq8064 supplies
  PCI: qcom: Add missing supplies required for msm8996
  PCI: designware-ep: Fix typo in error message

6 years agoMerge branch 'lorenzo/pci/altera'
Bjorn Helgaas [Wed, 4 Apr 2018 18:28:42 +0000 (13:28 -0500)]
Merge branch 'lorenzo/pci/altera'

* lorenzo/pci/altera:
  PCI: altera: Fix bool initialization in tlp_read_packet()

6 years agoMerge branch 'pci/vpd'
Bjorn Helgaas [Wed, 4 Apr 2018 18:28:40 +0000 (13:28 -0500)]
Merge branch 'pci/vpd'

  - consolidate VPD code in vpd.c (Bjorn Helgaas)

* pci/vpd:
  PCI/VPD: Move VPD structures to vpd.c
  PCI/VPD: Move VPD quirks to vpd.c
  PCI/VPD: Move VPD sysfs code to vpd.c
  PCI/VPD: Move VPD access code to vpd.c

6 years agoMerge branch 'pci/virtualization'
Bjorn Helgaas [Wed, 4 Apr 2018 18:28:26 +0000 (13:28 -0500)]
Merge branch 'pci/virtualization'

  - probe for device reset support during enumeration instead of runtime
    (Bjorn Helgaas)

  - add ACS quirk for Ampere (née APM) root ports (Feng Kan)

  - add function 1 DMA alias quirk for Marvell 88SE9220 (Thomas
    Vincent-Cross)

  - protect device restore with device lock (Sinan Kaya)

  - handle failure of FLR gracefully (Sinan Kaya)

  - handle CRS (config retry status) after device resets (Sinan Kaya)

  - skip various config reads for SR-IOV VFs as an optimization (KarimAllah
    Ahmed)

* pci/virtualization:
  PCI/IOV: Add missing prototypes for powerpc pcibios interfaces
  PCI/IOV: Use VF0 cached config registers for other VFs
  PCI/IOV: Skip BAR sizing for VFs
  PCI/IOV: Skip INTx config reads for VFs
  PCI: Wait for device to become ready after secondary bus reset
  PCI: Add a return type for pci_reset_bridge_secondary_bus()
  PCI: Wait for device to become ready after a power management reset
  PCI: Rename pci_flr_wait() to pci_dev_wait() and make it generic
  PCI: Handle FLR failure and allow other reset types
  PCI: Protect restore with device lock to be consistent
  PCI: Add function 1 DMA alias quirk for Marvell 88SE9220
  PCI: Add ACS quirk for Ampere root ports
  PCI: Remove redundant probes for device reset support
  PCI: Probe for device reset support during enumeration

Conflicts:
include/linux/pci.h

6 years agoMerge branch 'pci/sparc'
Bjorn Helgaas [Wed, 4 Apr 2018 18:28:13 +0000 (13:28 -0500)]
Merge branch 'pci/sparc'

  - support arbitrary PCI host bridge offsets on sparc (Yinghai Lu)

  - remove System and Video ROM reservations on sparc (Bjorn Helgaas)

* pci/sparc:
  sparc/PCI: Stop reserving System ROM and Video ROM in PCI space
  sparc/PCI: Support arbitrary host bridge address offset

6 years agoMerge branch 'pci/resource-mmap'
Bjorn Helgaas [Wed, 4 Apr 2018 18:28:11 +0000 (13:28 -0500)]
Merge branch 'pci/resource-mmap'

  - use generic pci_mmap_resource_range() instead of powerpc and xtensa
    arch-specific versions (David Woodhouse)

* pci/resource-mmap:
  xtensa/PCI: Use generic pci_mmap_resource_range()
  powerpc/pci: Use generic pci_mmap_resource_range()

6 years agoMerge branch 'pci/portdrv'
Bjorn Helgaas [Wed, 4 Apr 2018 18:27:58 +0000 (13:27 -0500)]
Merge branch 'pci/portdrv'

  - move pcieport_if.h to drivers/pci/pcie/ to encapsulate it (Frederick
    Lawler)

  - merge pcieport_if.h into portdrv.h (Bjorn Helgaas)

  - move workaround for BIOS PME issue from portdrv to PCI core (Bjorn
    Helgaas)

  - completely disable portdrv with "pcie_ports=compat" (Bjorn Helgaas)

  - remove portdrv link order dependency (Bjorn Helgaas)

  - remove support for unused VC portdrv service (Bjorn Helgaas)

  - simplify portdrv feature permission checking (Bjorn Helgaas)

  - remove "pcie_hp=nomsi" parameter (use "pci=nomsi" instead) (Bjorn
    Helgaas)

  - remove unnecessary "pcie_ports=auto" parameter (Bjorn Helgaas)

  - use cached AER capability offset (Frederick Lawler)

  - don't enable DPC if BIOS hasn't granted AER control (Mika Westerberg)

  - rename pcie-dpc.c to dpc.c (Bjorn Helgaas)

* pci/portdrv:
  PCI/DPC: Rename from pcie-dpc.c to dpc.c
  PCI/DPC: Do not enable DPC if AER control is not allowed by the BIOS
  PCI/AER: Use cached AER Capability offset
  PCI/portdrv: Rename and reverse sense of pcie_ports_auto
  PCI/portdrv: Encapsulate pcie_ports_auto inside the port driver
  PCI/portdrv: Remove unnecessary "pcie_ports=auto" parameter
  PCI/portdrv: Remove "pcie_hp=nomsi" kernel parameter
  PCI/portdrv: Remove unnecessary include of <linux/pci-aspm.h>
  PCI/portdrv: Simplify PCIe feature permission checking
  PCI/portdrv: Remove unused PCIE_PORT_SERVICE_VC
  PCI/portdrv: Remove pcie_port_bus_type link order dependency
  PCI/portdrv: Disable port driver in compat mode
  PCI/PM: Clear PCIe PME Status bit for Root Complex Event Collectors
  PCI/PM: Clear PCIe PME Status bit in core, not PCIe port driver
  PCI/PM: Move pcie_clear_root_pme_status() to core
  PCI/portdrv: Merge pcieport_if.h into portdrv.h
  PCI/portdrv: Move pcieport_if.h to drivers/pci/pcie/

Conflicts:
drivers/pci/pcie/Makefile
drivers/pci/pcie/portdrv.h

6 years agoMerge branch 'pci/msi'
Bjorn Helgaas [Wed, 4 Apr 2018 18:27:46 +0000 (13:27 -0500)]
Merge branch 'pci/msi'

  - don't set up INTx if MSI or MSI-X is enabled to align cris, frv, ia64,
    and mn10300 with x86 (Bjorn Helgaas)

* pci/msi:
  PCI/MSI: Don't set up INTx if MSI or MSI-X is enabled

6 years agoMerge branch 'pci/misc'
Bjorn Helgaas [Wed, 4 Apr 2018 18:27:45 +0000 (13:27 -0500)]
Merge branch 'pci/misc'

  - use PCI_EXP_DEVCTL2_COMP_TIMEOUT in rapidio/tsi721 (Bjorn Helgaas)

  - remove possible NULL pointer dereference in of_pci_bus_find_domain_nr()
    (Shawn Lin)

  - report quirk timings with dev_info (Bjorn Helgaas)

  - report quirks that take longer than 10ms (Bjorn Helgaas)

  - add and use Altera Vendor ID (Johannes Thumshirn)

  - tidy Makefiles and comments (Bjorn Helgaas)

* pci/misc:
  PCI: Always define the of_node helpers
  PCI: Tidy comments
  PCI: Tidy Makefiles
  mcb: Add Altera PCI ID to mcb-pci
  PCI: Add Altera vendor ID
  PCI: Report quirks that take more than 10ms
  PCI: Report quirk timings with pci_info() instead of pr_debug()
  PCI: Fix NULL pointer dereference in of_pci_bus_find_domain_nr()
  rapidio/tsi721: use PCI_EXP_DEVCTL2_COMP_TIMEOUT macro

6 years agoMerge branch 'pci/lpc'
Bjorn Helgaas [Wed, 4 Apr 2018 18:27:43 +0000 (13:27 -0500)]
Merge branch 'pci/lpc'

  - add support for PCI I/O port space that's neither directly accessible
    via CPU in/out instructions nor directly mapped into CPU physical
    memory space (Zhichang Yuan)

  - add support for HiSilicon Hip06/Hip07 LPC I/O space (Zhichang Yuan,
    John Garry)

* pci/lpc:
  MAINTAINERS: Add John Garry as maintainer for HiSilicon LPC driver
  HISI LPC: Add ACPI support
  ACPI / scan: Do not enumerate Indirect IO host children
  ACPI / scan: Rename acpi_is_serial_bus_slave() for more general use
  HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings
  of: Add missing I/O range exception for indirect-IO devices
  PCI: Apply the new generic I/O management on PCI IO hosts
  PCI: Add fwnode handler as input param of pci_register_io_range()
  PCI: Remove __weak tag from pci_register_io_range()
  lib: Add generic PIO mapping method

6 years agoMerge branch 'pci/hotplug'
Bjorn Helgaas [Wed, 4 Apr 2018 18:27:42 +0000 (13:27 -0500)]
Merge branch 'pci/hotplug'

  - fix possible cpqphp NULL pointer dereference (Shawn Lin)

  - rescan more of the hierarchy on ACPI hotplug to fix Thunderbolt/xHCI
    hotplug (Mika Westerberg)

* pci/hotplug:
  ACPI / hotplug / PCI: Check presence of slot itself in get_slot_status()
  PCI: cpqphp: Fix possible NULL pointer dereference

6 years agoMerge branch 'pci/enumeration'
Bjorn Helgaas [Wed, 4 Apr 2018 18:27:40 +0000 (13:27 -0500)]
Merge branch 'pci/enumeration'

  - add decoding for 16 GT/s link speed (Jay Fang)

  - add interfaces to get max link speed and width (Tal Gilboa)

  - add pcie_bandwidth_capable() to compute max supported link bandwidth
    (Tal Gilboa)

  - add pcie_bandwidth_available() to compute bandwidth available to device
    (Tal Gilboa)

  - add pcie_print_link_status() to log link speed and whether it's limited
    (Tal Gilboa)

  - use PCI core interfaces to report when device performance may be
    limited by its slot instead of doing it in each driver (Tal Gilboa)

* pci/enumeration:
  fm10k: Report PCIe link properties with pcie_print_link_status()
  net/mlx5e: Use pcie_bandwidth_available() to compute bandwidth
  net/mlx5: Report PCIe link properties with pcie_print_link_status()
  net/mlx4_core: Report PCIe link properties with pcie_print_link_status()
  PCI: Add pcie_print_link_status() to log link speed and whether it's limited
  PCI: Add pcie_bandwidth_available() to compute bandwidth available to device
  PCI: Add pcie_bandwidth_capable() to compute max supported link bandwidth
  PCI: Add pcie_get_width_cap() to find max supported link width
  PCI: Add pcie_get_speed_cap() to find max supported link speed
  PCI: Add decoding for 16 GT/s link speed

6 years agoMerge branch 'pci/deprecate-get-bus-and-slot'
Bjorn Helgaas [Wed, 4 Apr 2018 18:27:39 +0000 (13:27 -0500)]
Merge branch 'pci/deprecate-get-bus-and-slot'

  - remove last user of pci_get_bus_and_slot() and the function itself
    (Sinan Kaya)

* pci/deprecate-get-bus-and-slot:
  PCI: Remove pci_get_bus_and_slot() function
  drm/i915: Deprecate pci_get_bus_and_slot()

6 years agoMerge branch 'pci/aspm'
Bjorn Helgaas [Wed, 4 Apr 2018 18:27:37 +0000 (13:27 -0500)]
Merge branch 'pci/aspm'

  - skip ASPM common clock warning if BIOS already configured it (Sinan
    Kaya)

  - fix ASPM Coverity warning about threshold_ns (Gustavo A. R. Silva)

* pci/aspm:
  PCI/ASPM: Don't warn if already in common clock mode
  PCI/ASPM: Declare threshold_ns as u32, not u64

6 years agoMerge branch 'pci/aer'
Bjorn Helgaas [Wed, 4 Apr 2018 18:27:36 +0000 (13:27 -0500)]
Merge branch 'pci/aer'

  - move pci_uevent_ers() out of pci.h (Michael Ellerman)

* pci/aer:
  PCI/AER: Move pci_uevent_ers() out of pci.h

6 years agoMAINTAINERS: Add John Garry as maintainer for HiSilicon LPC driver
John Garry [Wed, 14 Mar 2018 18:15:59 +0000 (02:15 +0800)]
MAINTAINERS: Add John Garry as maintainer for HiSilicon LPC driver

Add John Garry as maintainer for drivers/bus/hisi_lpc.c, the HiSilicon LPC
driver.

Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoHISI LPC: Add ACPI support
John Garry [Wed, 14 Mar 2018 18:15:58 +0000 (02:15 +0800)]
HISI LPC: Add ACPI support

Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.

It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.

The ACPI table for the LPC host controller and the child devices is in the
following format:

  Device (LPC0) {
    Name (_HID, "HISI0191")  // HiSi LPC
    Name (_CRS, ResourceTemplate () {
      Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
    })
  }

  Device (LPC0.IPMI) {
    Name (_HID, "IPI0001")
    Name (LORS, ResourceTemplate() {
      QWordIO (
        ResourceConsumer,
        MinNotFixed,     // _MIF
        MaxNotFixed,     // _MAF
        PosDecode,
        EntireRange,
        0x0,             // _GRA
        0xe4,            // _MIN
        0x3fff,          // _MAX
        0x0,             // _TRA
        0x04,            // _LEN
        , ,
        BTIO
      )
    })

Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute.  The MFD IO resources will be the translated bus
addresses of the ACPI child.

Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
6 years agoACPI / scan: Do not enumerate Indirect IO host children
John Garry [Wed, 14 Mar 2018 18:15:57 +0000 (02:15 +0800)]
ACPI / scan: Do not enumerate Indirect IO host children

Through the logical PIO framework, systems which otherwise have no IO space
access to legacy ISA/LPC devices may access these devices through so-called
"indirect IO" method.  In this, IO space accesses for non-PCI hosts are
redirected to a host LLDD to manually generate the IO space (bus) accesses.
Hosts are able to register a region in logical PIO space to map to its bus
address range.

Indirect IO child devices have an associated host-specific bus address.
Special translation is required to map between a logical PIO address for a
device and its host bus address.

Since in the ACPI tables the child device IO resources would be the
host-specific values, it is required the ACPI scan code should not
enumerate these devices, and that this should be the responsibility of the
host driver so that it can "fixup" the resources so that they map to the
appropriate logical PIO addresses.

To avoid enumerating these child devices, add a check from
acpi_device_enumeration_by_parent() as to whether the parent for a device
is a member of a known list of "indirect IO" hosts.  For now, the HiSilicon
LPC host controller ID is added.

Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6 years agoACPI / scan: Rename acpi_is_serial_bus_slave() for more general use
John Garry [Wed, 14 Mar 2018 18:15:56 +0000 (02:15 +0800)]
ACPI / scan: Rename acpi_is_serial_bus_slave() for more general use

Currently the ACPI scan has special handling for serial bus slaves, in that
it makes it the responsibility of the slave device's parent to enumerate
the device.

To support other types of slave devices which require the same special
handling but where the bus is not strictly a serial bus, such as devices on
the HiSilicon LPC controller bus, rename acpi_is_serial_bus_slave() to
acpi_device_enumeration_by_parent(), so that the name can fit the wider
purpose.

Also rename the associated device flag acpi_device_flags.serial_bus_slave
to .enumeration_by_parent.

Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6 years agoHISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings
Zhichang Yuan [Wed, 21 Mar 2018 22:23:02 +0000 (17:23 -0500)]
HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings

The low-pin-count (LPC) interface of Hip06/Hip07 accesses I/O port space of
peripherals.

Implement the LPC host controller driver which performs the I/O operations
on the underlying hardware.  We don't want to touch existing drivers such
as ipmi-bt, so this driver applies the indirect-IO introduced in the
previous patch after registering an indirect-IO node to the indirect-IO
devices list which will be searched by the I/O accessors to retrieve the
host-local I/O port.

The driver config is set as a bool instead of a tristate.  The reason here
is that, by the very nature of the driver providing a logical PIO range, it
does not make sense to have this driver as a loadable module.  Another more
specific reason is that the Huawei D03 board which includes Hip06 SoC
requires the LPC bus for UART console, so should be built in.

Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: Zou Rongrong <zourongrong@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Rob Herring <robh@kernel.org> # dts part
6 years agoof: Add missing I/O range exception for indirect-IO devices
Zhichang Yuan [Wed, 14 Mar 2018 18:15:54 +0000 (02:15 +0800)]
of: Add missing I/O range exception for indirect-IO devices

There are some special ISA/LPC devices that work on a specific I/O range
where it is not correct to specify a 'ranges' property in the DTS parent
node as CPU addresses translated from DTS node are only for memory space on
some architectures, such as ARM64.  Without the parent 'ranges' property,
of_translate_address() returns an error.

Here we add special handling for this case.

During the OF address translation, some checking will be performed to
identify whether the device node is registered as indirect-IO.  If it is,
the I/O translation will be done in a different way from that one of PCI
MMIO.  In this way, the I/O 'reg' property of the special ISA/LPC devices
will be parsed correctly.

Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de> # earlier draft
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Rob Herring <robh@kernel.org>
6 years agoPCI: Apply the new generic I/O management on PCI IO hosts
Zhichang Yuan [Wed, 14 Mar 2018 18:15:53 +0000 (02:15 +0800)]
PCI: Apply the new generic I/O management on PCI IO hosts

After introducing the new generic I/O space management (Logical PIO), the
original PCI MMIO relevant helpers need to be updated based on the new
interfaces defined in logical PIO.

Adapt the corresponding code to match the changes introduced by logical
PIO.

Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de> # earlier draft
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
6 years agoPCI: Add fwnode handler as input param of pci_register_io_range()
Gabriele Paoloni [Wed, 14 Mar 2018 18:15:52 +0000 (02:15 +0800)]
PCI: Add fwnode handler as input param of pci_register_io_range()

In preparation for having the PCI MMIO helpers use the new generic I/O
space management (logical PIO) we need to add the fwnode handler as an
extra input parameter.

Changes the signature of pci_register_io_range() and its callers as
needed.

Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Rob Herring <robh@kernel.org>
6 years agoPCI: Remove __weak tag from pci_register_io_range()
Gabriele Paoloni [Wed, 14 Mar 2018 18:15:51 +0000 (02:15 +0800)]
PCI: Remove __weak tag from pci_register_io_range()

pci_register_io_range() has only one definition, so there is no need for
the __weak attribute.  Remove it.

Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
6 years agofm10k: Report PCIe link properties with pcie_print_link_status()
Bjorn Helgaas [Fri, 30 Mar 2018 19:22:44 +0000 (14:22 -0500)]
fm10k: Report PCIe link properties with pcie_print_link_status()

Previously the driver used pcie_get_minimum_link() to warn when the NIC
is in a slot that can't supply as much bandwidth as the NIC could use.

pcie_get_minimum_link() can be misleading because it finds the slowest link
and the narrowest link (which may be different links) without considering
the total bandwidth of each link.  For a path with a 16 GT/s x1 link and a
2.5 GT/s x16 link, it returns 2.5 GT/s x1, which corresponds to 250 MB/s of
bandwidth, not the true available bandwidth of about 1969 MB/s for a
16 GT/s x1 link.

Use pcie_print_link_status() to report PCIe link speed and possible
limitations instead of implementing this in the driver itself.  This finds
the slowest link in the path to the device by computing the total bandwidth
of each link and compares that with the capabilities of the device.

Note that the driver previously used dev_warn() to suggest using a
different slot, but pcie_print_link_status() uses dev_info() because if the
platform has no faster slot available, the user can't do anything about the
warning and may not want to be bothered with it.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Jacob Keller <jacob.e.keller@intel.com>
6 years agonet/mlx5e: Use pcie_bandwidth_available() to compute bandwidth
Tal Gilboa [Fri, 30 Mar 2018 14:01:51 +0000 (09:01 -0500)]
net/mlx5e: Use pcie_bandwidth_available() to compute bandwidth

Use the new pci_bandwidth_available() function to calculate maximum
available bandwidth through the PCI chain instead of computing it ourselves
with mlx5e_get_pci_bw().

This is used to detect when the device is capable of more bandwidth than is
available in the current slot.  The driver may adjust compression settings
accordingly.

Note that pci_bandwidth_available() accounts for PCIe encoding overhead, so
it is more accurate than mlx5e_get_pci_bw() was.

Signed-off-by: Tal Gilboa <talgi@mellanox.com>
[bhelgaas: remove mlx5e_get_pci_bw() wrapper altogether]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Tariq Toukan <tariqt@mellanox.com>
6 years agonet/mlx5: Report PCIe link properties with pcie_print_link_status()
Tal Gilboa [Fri, 30 Mar 2018 14:01:34 +0000 (09:01 -0500)]
net/mlx5: Report PCIe link properties with pcie_print_link_status()

Use pcie_print_link_status() to report PCIe link speed and possible
limitations.

Signed-off-by: Tal Gilboa <talgi@mellanox.com>
[bhelgaas: changelog]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Tariq Toukan <tariqt@mellanox.com>
6 years agonet/mlx4_core: Report PCIe link properties with pcie_print_link_status()
Tal Gilboa [Fri, 30 Mar 2018 14:01:05 +0000 (09:01 -0500)]
net/mlx4_core: Report PCIe link properties with pcie_print_link_status()

Use pcie_print_link_status() to report PCIe link speed and possible
limitations instead of implementing this in the driver itself.

Signed-off-by: Tal Gilboa <talgi@mellanox.com>
Signed-off-by: Tariq Toukan <tariqt@mellanox.com>
[bhelgaas: changelog]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI: Add pcie_print_link_status() to log link speed and whether it's limited
Tal Gilboa [Fri, 30 Mar 2018 13:56:47 +0000 (08:56 -0500)]
PCI: Add pcie_print_link_status() to log link speed and whether it's limited

Add pcie_print_link_status().  This logs the current settings of the link
(speed, width, and total available bandwidth).

If the device is capable of more bandwidth but is limited by a slower
upstream link, we include information about the link that limits the
device's performance.

The user may be able to move the device to a different slot for better
performance.

This provides a unified method for all PCI devices to report status and
issues, instead of each device reporting in a different way, using
different code.

Signed-off-by: Tal Gilboa <talgi@mellanox.com>
[bhelgaas: changelog, reword log messages, print device capabilities when
not limited, print bandwidth in Gb/s]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI: Add pcie_bandwidth_available() to compute bandwidth available to device
Tal Gilboa [Fri, 30 Mar 2018 13:37:44 +0000 (08:37 -0500)]
PCI: Add pcie_bandwidth_available() to compute bandwidth available to device

Add pcie_bandwidth_available() to compute the bandwidth available to a
device.  This may be limited by the device itself or by a slower upstream
link leading to the device.

The available bandwidth at each link along the path is computed as:

  link_width * link_speed * (1 - encoding_overhead)

2.5 and 5.0 GT/s links use 8b/10b encoding, which reduces the raw bandwidth
available by 20%; 8.0 GT/s and faster links use 128b/130b encoding, which
reduces it by about 1.5%.

The result is in Mb/s, i.e., megabits/second, of raw bandwidth.

Also return the device with the slowest link and the speed and width of
that link.

Signed-off-by: Tal Gilboa <talgi@mellanox.com>
[bhelgaas: changelog, leave pcie_get_minimum_link() alone for now, return
bw directly, use pci_upstream_bridge(), check "next_bw <= bw" to find
uppermost limiting device, return speed/width of the limiting device]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI/DPC: Rename from pcie-dpc.c to dpc.c
Bjorn Helgaas [Sat, 31 Mar 2018 22:48:57 +0000 (17:48 -0500)]
PCI/DPC: Rename from pcie-dpc.c to dpc.c

Rename pcie-dpc.c to dpc.c.  The path "drivers/pci/pcie/pcie-dpc.c" has
more occurrences of "pci" than necessary.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI/IOV: Add missing prototypes for powerpc pcibios interfaces
Mathieu Malaterre [Fri, 30 Mar 2018 22:39:31 +0000 (17:39 -0500)]
PCI/IOV: Add missing prototypes for powerpc pcibios interfaces

Add missing prototypes for:

  resource_size_t pcibios_default_alignment(void);
  int pcibios_sriov_enable(struct pci_dev *pdev, u16 num_vfs);
  int pcibios_sriov_disable(struct pci_dev *pdev);

This fixes the following warnings treated as errors when using W=1:

  arch/powerpc/kernel/pci-common.c:236:17: error: no previous prototype for ‘pcibios_default_alignment’ [-Werror=missing-prototypes]
  arch/powerpc/kernel/pci-common.c:253:5: error: no previous prototype for ‘pcibios_sriov_enable’ [-Werror=missing-prototypes]
  arch/powerpc/kernel/pci-common.c:261:5: error: no previous prototype for ‘pcibios_sriov_disable’ [-Werror=missing-prototypes]

Also, commit 978d2d683123 ("PCI: Add pcibios_iov_resource_alignment()
interface") added a new function but the prototype was located in the main
header instead of the CONFIG_PCI_IOV specific section.  Move this function
next to the newly added ones.

Signed-off-by: Mathieu Malaterre <malat@debian.org>
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
6 years agoPCI/IOV: Use VF0 cached config registers for other VFs
KarimAllah Ahmed [Mon, 19 Mar 2018 20:06:00 +0000 (21:06 +0100)]
PCI/IOV: Use VF0 cached config registers for other VFs

Cache some config data from VF0 and use it for all other VFs instead of
reading it from the config space of each VF.  We assume these items are the
same across all associated VFs:

   Revision ID
   Class Code
   Subsystem Vendor ID
   Subsystem ID

This is an optimization when enabling SR-IOV on a device with many VFs.

Signed-off-by: KarimAllah Ahmed <karahmed@amazon.de>
[bhelgaas: changelog, simplify comments, remove unused "device", test
CONFIG_PCI_IOV instead of CONFIG_PCI_ATS, rename functions]
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
6 years agoPCI: Always define the of_node helpers
Bjørn Mork [Sun, 18 Mar 2018 12:58:06 +0000 (13:58 +0100)]
PCI: Always define the of_node helpers

Simply move these inline functions outside the ifdef instead of duplicating
them as stubs in the !OF case.  The struct device of_node field does not
depend on OF.

This also fixes the missing stubbed pci_bus_to_OF_node().

Signed-off-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
6 years agoPCI/DPC: Do not enable DPC if AER control is not allowed by the BIOS
Mika Westerberg [Tue, 27 Mar 2018 10:48:35 +0000 (13:48 +0300)]
PCI/DPC: Do not enable DPC if AER control is not allowed by the BIOS

Commit eed85ff4c0da ("PCI/DPC: Enable DPC only if AER is available") made
DPC control dependent whether AER is enabled in the OS.  However, it does
not take into account situations where BIOS has not given OS control of
AER:

  acpi PNP0A08:00: _OSC: OS supports [ExtendedConfig ASPM ClockPM Segments MSI]
  acpi PNP0A08:00: _OSC: platform does not support [AER]
  acpi PNP0A08:00: _OSC: OS now controls [PCIeHotplug PME PCIeCapability]

I think here it is better not to enable DPC even if the capability is
available because then it would be against what "Determination of DPC
Control" note in PCIe 4.0 sec 6.1.10 recommends.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
6 years agoPCI/AER: Use cached AER Capability offset
Frederick Lawler [Thu, 22 Mar 2018 21:20:55 +0000 (16:20 -0500)]
PCI/AER: Use cached AER Capability offset

Replace pci_find_ext_capability(..., PCI_EXT_CAP_ID_ERR) calls with
pci_dev->aer_cap.

pci_dev->aer_cap is initialized in pci_init_capabilities(), which happens
before any of these users of the AER Capability.

Signed-off-by: Frederick Lawler <fred@fredlawl.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI/portdrv: Rename and reverse sense of pcie_ports_auto
Bjorn Helgaas [Fri, 9 Mar 2018 17:21:30 +0000 (11:21 -0600)]
PCI/portdrv: Rename and reverse sense of pcie_ports_auto

The platform may restrict the OS's use of PCIe services, e.g., via the ACPI
_OSC method.  The user may use "pcie_ports=native" to force the port driver
to use PCIe services even if the platform asked us not to.

The "pcie_ports=native" parameter determines the setting of
pcie_ports_auto.  Rename this to pcie_ports_native and reverse the
sense to simplify the code.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI/portdrv: Encapsulate pcie_ports_auto inside the port driver
Bjorn Helgaas [Fri, 9 Mar 2018 17:21:29 +0000 (11:21 -0600)]
PCI/portdrv: Encapsulate pcie_ports_auto inside the port driver

"pcie_ports_auto" is only used inside the PCIe port driver itself, so
move it from include/linux/pci.h to portdrv.h so it's not visible to the
whole kernel.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI/portdrv: Remove unnecessary "pcie_ports=auto" parameter
Bjorn Helgaas [Fri, 9 Mar 2018 17:21:28 +0000 (11:21 -0600)]
PCI/portdrv: Remove unnecessary "pcie_ports=auto" parameter

The "pcie_ports=auto" parameter set pcie_ports_disabled and pcie_ports_auto
to their compiled-in defaults, so specifying the parameter is the same as
not using it at all.

Remove the "pcie_ports=auto" parameter and update the documentation.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI/portdrv: Remove "pcie_hp=nomsi" kernel parameter
Bjorn Helgaas [Fri, 9 Mar 2018 17:21:27 +0000 (11:21 -0600)]
PCI/portdrv: Remove "pcie_hp=nomsi" kernel parameter

7570a333d8b0 ("PCI: Add pcie_hp=nomsi to disable MSI/MSI-X for pciehp
driver") added the "pcie_hp=nomsi" kernel parameter to work around this
error on shutdown:

  irq 16: nobody cared (try booting with the "irqpoll" option)
  Pid: 1081, comm: reboot Not tainted 3.2.0 #1
  ...
  Disabling IRQ #16

This happened on an unspecified system (possibly involving the Integrated
Device Technology, Inc. Device 807f bridge) where "an un-wanted interrupt
is generated when PCI driver switches from MSI/MSI-X to INTx while shutting
down the device."

The implication was that the device was buggy, but it is normal for a
device to use INTx after MSI/MSI-X have been disabled.  The only problem
was that the driver was still attached and it wasn't prepared for INTx
interrupts.  Prarit Bhargava fixed this issue with fda78d7a0ead ("PCI/MSI:
Stop disabling MSI/MSI-X in pci_device_shutdown()").

There is no automated way to set this parameter, so it's not very useful
for distributions or end users.  It's really only useful for debugging, and
we have "pci=nomsi" for that purpose.

Revert 7570a333d8b0 to remove the "pcie_hp=nomsi" parameter.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
CC: MUNEDA Takahiro <muneda.takahiro@jp.fujitsu.com>
CC: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
CC: Prarit Bhargava <prarit@redhat.com>
6 years agoPCI/portdrv: Remove unnecessary include of <linux/pci-aspm.h>
Bjorn Helgaas [Fri, 9 Mar 2018 17:21:26 +0000 (11:21 -0600)]
PCI/portdrv: Remove unnecessary include of <linux/pci-aspm.h>

portdrv_pci.c doesn't use anything from <linux/pci-aspm.h>.  Remove the
include of it.  No functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6 years agoPCI/portdrv: Simplify PCIe feature permission checking
Bjorn Helgaas [Fri, 9 Mar 2018 17:21:25 +0000 (11:21 -0600)]
PCI/portdrv: Simplify PCIe feature permission checking

Some PCIe features (AER, DPC, hotplug, PME) can be managed by either the
platform firmware or the OS, so the host bridge driver may have to request
permission from the platform before using them.  On ACPI systems, this is
done by negotiate_os_control() in acpi_pci_root_add().

The PCIe port driver later uses pcie_port_platform_notify() and
pcie_port_acpi_setup() to figure out whether it can use these features.
But all we need is a single bit for each service, so these interfaces are
needlessly complicated.

Simplify this by adding bits in the struct pci_host_bridge to show when the
OS has permission to use each feature:

  + unsigned int native_aer:1;       /* OS may use PCIe AER */
  + unsigned int native_hotplug:1;   /* OS may use PCIe hotplug */
  + unsigned int native_pme:1;       /* OS may use PCIe PME */

These are set when we create a host bridge, and the host bridge driver can
clear the bits corresponding to any feature the platform doesn't want us to
use.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6 years agoPCI/portdrv: Remove unused PCIE_PORT_SERVICE_VC
Bjorn Helgaas [Fri, 9 Mar 2018 17:21:24 +0000 (11:21 -0600)]
PCI/portdrv: Remove unused PCIE_PORT_SERVICE_VC

No driver registers for PCIE_PORT_SERVICE_VC, so remove it.

This removes the VC "service" files from /sys/bus/pci_express/devices,
e.g., 0000:07:00.0:pcie108, 0000:08:04.0:pcie208 (all the files that
contained "8" as the last digit of the "pcieXXX" part).  The port driver
created these files for PCIe port devices that have a VC Capability.

Since this reduces PCIE_PORT_DEVICE_MAXSERVICES and moves DPC down into the
spot where VC used to be, the DPC sysfs files will now be named "pcieXX8".
I don't think there's anything useful userspace can do with those files, so
I hope nobody cares about these filenames.

There is no VC driver that calls pcie_port_service_register(), so there
never was a /sys/bus/pci_express/drivers/vc directory.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
6 years agoPCI/portdrv: Remove pcie_port_bus_type link order dependency
Bjorn Helgaas [Fri, 9 Mar 2018 17:06:56 +0000 (11:06 -0600)]
PCI/portdrv: Remove pcie_port_bus_type link order dependency

The pcie_port_bus_type must be registered before drivers that depend on it
can be registered.  Those drivers include:

  pcied_init()                # PCIe native hotplug driver
  aer_service_init()          # AER driver
  dpc_service_init()          # DPC driver
  pcie_pme_service_init()     # PME driver

Previously we registered pcie_port_bus_type from pcie_portdrv_init(), a
device_initcall.  The callers of pcie_port_service_register() (above) are
also device_initcalls.  This is fragile because the device_initcall
ordering depends on link order, which is not explicit.

Register pcie_port_bus_type from pci_driver_init() along with pci_bus_type.
This removes the link order dependency between portdrv and the pciehp, AER,
DPC, and PCIe PME drivers.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
6 years agoPCI/portdrv: Disable port driver in compat mode
Bjorn Helgaas [Fri, 9 Mar 2018 17:06:56 +0000 (11:06 -0600)]
PCI/portdrv: Disable port driver in compat mode

The "pcie_ports=compat" kernel parameter sets pcie_ports_disabled, which is
intended to disable the PCIe port driver.  But even when it was disabled,
we registered pcie_portdriver so we could work around a BIOS PME issue (see
fe31e69740ed ("PCI/PCIe: Clear Root PME Status bits early during system
resume")).

Registering the driver meant that the pcie_portdrv_probe() path called
pci_enable_device(), pci_save_state(), pm_runtime_set_autosuspend_delay(),
pm_runtime_use_autosuspend(), etc., even when the driver was disabled.

We've since moved the BIOS PME workaround from the port driver to the core,
so stop registering the PCIe port driver in compat mode.

This means "pcie_ports=compat" will now be basically the same as turning
off CONFIG_PCIEPORTBUS completely.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6 years agoPCI/PM: Clear PCIe PME Status bit for Root Complex Event Collectors
Bjorn Helgaas [Fri, 9 Mar 2018 17:06:55 +0000 (11:06 -0600)]
PCI/PM: Clear PCIe PME Status bit for Root Complex Event Collectors

Per PCIe r4.0, sec 6.1.6, Root Complex Event Collectors can generate PME
interrupts on behalf of Root Complex Integrated Endpoints.

Linux does not currently enable PME interrupts from RC Event Collectors,
but fe31e69740ed ("PCI/PCIe: Clear Root PME Status bits early during system
resume") suggests PME interrupts may be enabled by the platform for ACPI-
based runtime wakeup.

Clear the PCIe PME Status bit for Root Complex Event Collectors during
resume, just like we already do for Root Ports.

If the BIOS enables PME interrupts for an event collector and neglects to
clear the status bit on resume, this change should fix the same bug as
fe31e69740ed (PMEs not working after waking from a sleep state), but for
Root Complex Integrated Endpoints.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6 years agoPCI: Add pcie_bandwidth_capable() to compute max supported link bandwidth
Tal Gilboa [Fri, 30 Mar 2018 13:32:03 +0000 (08:32 -0500)]
PCI: Add pcie_bandwidth_capable() to compute max supported link bandwidth

Add pcie_bandwidth_capable() to compute the max link bandwidth supported by
a device, based on the max link speed and width, adjusted by the encoding
overhead.

The maximum bandwidth of the link is computed as:

  max_link_width * max_link_speed * (1 - encoding_overhead)

2.5 and 5.0 GT/s links use 8b/10b encoding, which reduces the raw bandwidth
available by 20%; 8.0 GT/s and faster links use 128b/130b encoding, which
reduces it by about 1.5%.

The result is in Mb/s, i.e., megabits/second, of raw bandwidth.

Signed-off-by: Tal Gilboa <talgi@mellanox.com>
[bhelgaas: add 16 GT/s, adjust for pcie_get_speed_cap() and
pcie_get_width_cap() signatures, don't export outside drivers/pci]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI: Add pcie_get_width_cap() to find max supported link width
Tal Gilboa [Fri, 30 Mar 2018 13:24:36 +0000 (08:24 -0500)]
PCI: Add pcie_get_width_cap() to find max supported link width

Add pcie_get_width_cap() to find the max link width supported by a device.
Change max_link_width_show() to use pcie_get_width_cap().

Signed-off-by: Tal Gilboa <talgi@mellanox.com>
[bhelgaas: return width directly instead of error and *width, don't export
outside drivers/pci]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Tariq Toukan <tariqt@mellanox.com>
6 years agoPCI: Add pcie_get_speed_cap() to find max supported link speed
Tal Gilboa [Fri, 30 Mar 2018 12:44:05 +0000 (07:44 -0500)]
PCI: Add pcie_get_speed_cap() to find max supported link speed

Add pcie_get_speed_cap() to find the max link speed supported by a device.
Change max_link_speed_show() to use pcie_get_speed_cap().

Signed-off-by: Tal Gilboa <talgi@mellanox.com>
[bhelgaas: return speed directly instead of error and *speed, don't export
outside drivers/pci]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Tariq Toukan <tariqt@mellanox.com>
6 years agoACPI / hotplug / PCI: Check presence of slot itself in get_slot_status()
Mika Westerberg [Mon, 12 Feb 2018 10:55:23 +0000 (13:55 +0300)]
ACPI / hotplug / PCI: Check presence of slot itself in get_slot_status()

Mike Lothian reported that plugging in a USB-C device does not work
properly in his Dell Alienware system.  This system has an Intel Alpine
Ridge Thunderbolt controller providing USB-C functionality.  In these
systems the USB controller (xHCI) is hotplugged whenever a device is
connected to the port using ACPI-based hotplug.

The ACPI description of the root port in question is as follows:

  Device (RP01)
  {
      Name (_ADR, 0x001C0000)

      Device (PXSX)
      {
          Name (_ADR, 0x02)

          Method (_RMV, 0, NotSerialized)
          {
              // ...
          }
      }

Here _ADR 0x02 means device 0, function 2 on the bus under root port (RP01)
but that seems to be incorrect because device 0 is the upstream port of the
Alpine Ridge PCIe switch and it has no functions other than 0 (the bridge
itself).  When we get ACPI Notify() to the root port resulting from
connecting a USB-C device, Linux tries to read PCI_VENDOR_ID from device 0,
function 2 which of course always returns 0xffffffff because there is no
such function and we never find the device.

In Windows this works fine.

Now, since we get ACPI Notify() to the root port and not to the PXSX device
we should actually start our scan from there as well and not from the
non-existent PXSX device.  Fix this by checking presence of the slot itself
(function 0) if we fail to do that otherwise.

While there use pci_bus_read_dev_vendor_id() in get_slot_status(), which is
the recommended way to read Device and Vendor IDs of devices on PCI buses.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=198557
Reported-by: Mike Lothian <mike@fireburn.co.uk>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org
6 years agolib: Add generic PIO mapping method
Zhichang Yuan [Wed, 14 Mar 2018 18:15:50 +0000 (02:15 +0800)]
lib: Add generic PIO mapping method

41f8bba7f555 ("of/pci: Add pci_register_io_range() and
pci_pio_to_address()") added support for PCI I/O space mapped into CPU
physical memory space.  With that support, the I/O ranges configured for
PCI/PCIe hosts on some architectures can be mapped to logical PIO and
converted easily between CPU address and the corresponding logical PIO.
Based on this, PCI I/O port space can be accessed via in/out accessors that
use memory read/write.

But on some platforms, there are bus hosts that access I/O port space with
host-local I/O port addresses rather than memory addresses.

Add a more generic I/O mapping method to support those devices.  With this
patch, both the CPU addresses and the host-local port can be mapped into
the logical PIO space with different logical/fake PIOs.  After this, all
the I/O accesses to either PCI MMIO devices or host-local I/O peripherals
can be unified into the existing I/O accessors defined in asm-generic/io.h
and be redirected to the right device-specific hooks based on the input
logical PIO.

Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: John Garry <john.garry@huawei.com>
[bhelgaas: remove -EFAULT return from logic_pio_register_range() per
https://lkml.kernel.org/r/20180403143909.GA21171@ulmo, fix NULL pointer
checking per https://lkml.kernel.org/r/20180403211505.GA29612@embeddedor.com]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
6 years agoPCI: Add decoding for 16 GT/s link speed
Jay Fang [Mon, 12 Mar 2018 09:13:32 +0000 (17:13 +0800)]
PCI: Add decoding for 16 GT/s link speed

PCIe 4.0 defines the 16.0 GT/s link speed.  Links can run at that speed
without any Linux changes, but previously their sysfs "max_link_speed" and
"current_link_speed" files contained "Unknown speed", not the expected
"16.0 GT/s".

Add decoding for the new 16 GT/s link speed.

Signed-off-by: Jay Fang <f.fangjian@huawei.com>
[bhelgaas: add PCI_EXP_LNKCAP2_SLS_16_0GB]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Dongdong Liu <liudongdong3@huawei.com>
6 years agosparc/PCI: Stop reserving System ROM and Video ROM in PCI space
Bjorn Helgaas [Thu, 15 Feb 2018 21:07:39 +0000 (15:07 -0600)]
sparc/PCI: Stop reserving System ROM and Video ROM in PCI space

Previously, pci_register_legacy_regions() reserved PCI address space under
every PCI host bridge for the System ROM and the Video ROM, but these
regions are not part of PCI address space.

Previously, pci_register_legacy_regions() reserved the following areas of
PCI address space under every PCI host bridge:

  [bus 0xa0000-0xbffff]    Video RAM area (VGA frame buffer)
  [bus 0xc0000-0xc7fff]    Video ROM
  [bus 0xf0000-0xfffff]    System ROM

It does need to reserve the [bus 0xa0000-0xbffff] region (at least if
there's a possibility of a VGA device below the bridge) because VGA devices
can respond to that even if they don't describe it with a BAR.

But the Video ROM and System ROM areas don't seem necessary because they
are not areas that legacy PCI devices respond to.

They appear to be copied from x86, where they describe areas of system
memory that depend on BIOS conventions.  On x86, BIOS copies the option ROM
of the primary VGA device to RAM at 0xc0000, and the 0xf0000-0xfffff region
is reserved for the motherboard BIOS.  Neither of these things applies to
sparc.

Stop reserving the System ROM and Video ROM regions in PCI space.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: David S. Miller <davem@davemloft.net>
6 years agoPCI/IOV: Skip BAR sizing for VFs
KarimAllah Ahmed [Sat, 3 Mar 2018 04:33:10 +0000 (05:33 +0100)]
PCI/IOV: Skip BAR sizing for VFs

Per PCIe r4.0, sec 9.3.4.1.11, the BAR registers in VF config space are all
RO Zero, so skip sizing them.

This is an optimization when enabling SR-IOV on a device with many VFs.

Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: KarimAllah Ahmed <karahmed@amazon.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI: Tidy comments
Bjorn Helgaas [Fri, 9 Mar 2018 22:36:33 +0000 (16:36 -0600)]
PCI: Tidy comments

Remove pointless comments that tell us the file name, remove blank line
comments, follow multi-line comment conventions.  No functional change
intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI: Tidy Makefiles
Bjorn Helgaas [Fri, 9 Mar 2018 19:09:29 +0000 (13:09 -0600)]
PCI: Tidy Makefiles

Indent things so they line up neatly and remove extra blank lines and
superfluous comments.  No functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agomcb: Add Altera PCI ID to mcb-pci
Johannes Thumshirn [Mon, 12 Mar 2018 09:41:19 +0000 (10:41 +0100)]
mcb: Add Altera PCI ID to mcb-pci

Some older PCI-attached MEN FPGAs use an Altera PCI Vendor ID instead of
the MEN one. Add it to the PCI ID table so the driver automatically
attaches to it.

Reported-by: Ben Turner <ben.turner@21net.com>
Tested-by: Ben Turner <ben.turner@21net.com>
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Andreas Geißler <andreas.geissler@men.de>
6 years agoPCI: Add Altera vendor ID
Johannes Thumshirn [Mon, 12 Mar 2018 09:41:18 +0000 (10:41 +0100)]
PCI: Add Altera vendor ID

Add the Altera PCI Vendor id to pci_ids.h and remove the private
definitions from xillybus_pcie.c and altera-cvp.c.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Eli Billauer <eli.billauer@gmail.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Anatolij Gustschin <agust@denx.de>
6 years agoPCI: Report quirks that take more than 10ms
Bjorn Helgaas [Wed, 14 Mar 2018 12:52:30 +0000 (07:52 -0500)]
PCI: Report quirks that take more than 10ms

With "initcall_debug", we report how long every PCI quirk took.

Even without "initcall_debug", report the runtime of any quirk that takes
longer than 10ms.  This is to make it easier to notice quirks that slow
down boot.

This was motivated by a report from Paul Menzel that PCI final quirks took
half a second at boot.

Link: https://lkml.kernel.org/r/44cada166e42007d27b4c3e3aa0744d7@molgen.mpg.de
Reported-by: Paul Menzel <pmenzel@molgen.mpg.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI: Report quirk timings with pci_info() instead of pr_debug()
Bjorn Helgaas [Wed, 14 Mar 2018 12:42:56 +0000 (07:42 -0500)]
PCI: Report quirk timings with pci_info() instead of pr_debug()

With "initcall_debug", we report how long every PCI quirk took.  Previously
we used pr_debug(), which means you have to figure out how to enable debug
output.

Log these timings using pci_info() instead so it doesn't depend on DEBUG,
CONFIG_DYNAMIC_DEBUG, etc.

Also, don't log anything at all unless "initcall_debug" is specified.  This
matches what we do in do_one_initcall_debug().

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI/VPD: Move VPD structures to vpd.c
Bjorn Helgaas [Mon, 19 Mar 2018 18:06:34 +0000 (13:06 -0500)]
PCI/VPD: Move VPD structures to vpd.c

The VPD-related structures are only used in vpd.c, so move them from
drivers/pci/pci.h to vpd.c.  No functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI/VPD: Move VPD quirks to vpd.c
Bjorn Helgaas [Mon, 19 Mar 2018 18:06:24 +0000 (13:06 -0500)]
PCI/VPD: Move VPD quirks to vpd.c

Move the VPD-related quirks from quirks.c to vpd.c, which removes the need
for struct pci_vpd outside vpd.c.  The goal is to encapsulate all the VPD
code and structures in vpd.c.

No functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI/VPD: Move VPD sysfs code to vpd.c
Bjorn Helgaas [Mon, 19 Mar 2018 18:06:17 +0000 (13:06 -0500)]
PCI/VPD: Move VPD sysfs code to vpd.c

Move the VPD-related sysfs code from pci-sysfs.c to vpd.c.  This follows
the pattern of pcie_aspm_create_sysfs_dev_files().  The goal is to
encapsulate all the VPD code and structures in vpd.c.

No functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI/VPD: Move VPD access code to vpd.c
Bjorn Helgaas [Mon, 19 Mar 2018 18:06:11 +0000 (13:06 -0500)]
PCI/VPD: Move VPD access code to vpd.c

Move the VPD-related code from access.c to vpd.c.  The goal is to
encapsulate all the VPD code and structures in vpd.c.

No functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI/MSI: Don't set up INTx if MSI or MSI-X is enabled
Bjorn Helgaas [Tue, 13 Mar 2018 20:03:36 +0000 (15:03 -0500)]
PCI/MSI: Don't set up INTx if MSI or MSI-X is enabled

If MSI or MSI-X is enabled, the device uses that.  It uses INTx only if
both MSI and MSI-X are disabled (see PCIe r4.0, sec 7.7.1.2), so if a
device already has MSI or MSI-X enabled, there's no need to set up its
legacy INTx interrupt.

bba6f6fc68e7 ("[PATCH] MSI-X: fix resume crash") changed the cris, frv,
x86, and ia64 arches to skip INTx setup when MSI is enabled.  The cris and
frv arches have since been removed.

16cf0ebc35dd ("x86/PCI: Do not use interrupt links for devices using
MSI-X") extended that by changing x86 to also skip INTx setup when MSI-X is
enabled.

Change ia64 to skip INTx setup when either MSI or MSI-X is enabled by
applying the logic from 16cf0ebc35dd to ia64 as well as x86.

Tested-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
6 years agoPCI/PM: Clear PCIe PME Status bit in core, not PCIe port driver
Bjorn Helgaas [Fri, 9 Mar 2018 17:06:54 +0000 (11:06 -0600)]
PCI/PM: Clear PCIe PME Status bit in core, not PCIe port driver

fe31e69740ed ("PCI/PCIe: Clear Root PME Status bits early during system
resume") added a .resume_noirq() callback to the PCIe port driver to clear
the PME Status bit during resume to work around a BIOS issue.

The BIOS evidently enabled PME interrupts for ACPI-based runtime wakeups
but did not clear the PME Status bit during resume, which meant PMEs after
resume did not trigger interrupts because PME Status did not transition
from cleared to set.

The fix was in the PCIe port driver, so it worked when CONFIG_PCIEPORTBUS
was set.  But I think we *always* want the fix because the platform may use
PME interrupts even if Linux is built without the PCIe port driver.

Move the fix from the port driver to the PCI core so we can work around
this "PME doesn't work after waking from a sleep state" issue regardless of
CONFIG_PCIEPORTBUS.

[bhelgaas: folded in warning fix from Arnd Bergmann <arnd@arndb.de>:
https://lkml.kernel.org/r/20180328134747.2062348-1-arnd@arndb.de]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI/PM: Move pcie_clear_root_pme_status() to core
Bjorn Helgaas [Fri, 9 Mar 2018 17:06:53 +0000 (11:06 -0600)]
PCI/PM: Move pcie_clear_root_pme_status() to core

Move pcie_clear_root_pme_status() from the port driver to the PCI core so
it will be available even when the port driver isn't present.  No
functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
6 years agoPCI/portdrv: Merge pcieport_if.h into portdrv.h
Bjorn Helgaas [Fri, 9 Mar 2018 17:42:01 +0000 (11:42 -0600)]
PCI/portdrv: Merge pcieport_if.h into portdrv.h

pcieport_if.h contained the interfaces to register port service driver,
e.g., pcie_port_service_register().  portdrv.h contained internal data
structures of the port driver.

I don't think it's worth keeping those files separate, since both headers
and their users are all inside the PCI core.

Merge pcieport_if.h directly in drivers/pci/pcie/portdrv.h and update the
users to include that instead.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
6 years agoPCI: histb: Add an optional regulator for PCIe port power control
Shawn Guo [Fri, 2 Mar 2018 01:12:01 +0000 (09:12 +0800)]
PCI: histb: Add an optional regulator for PCIe port power control

The power supplies to PCIe port are often controlled by GPIO on some board
designs.  Let's add an optional regulator which can be backed by GPIO to
control the power.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Rob Herring <robh@kernel.org>
6 years agoPCI: histb: Fix error path of histb_pcie_host_enable()
Shawn Guo [Fri, 2 Mar 2018 01:12:00 +0000 (09:12 +0800)]
PCI: histb: Fix error path of histb_pcie_host_enable()

If clk_prepare_enable() call fails on a particular clock, we should not
call clk_disable_unprepare() on this clock, but on the clocks that
succeed from clk_prepare_enable() previously.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
6 years agoPCI: qcom: Use regulator bulk api for apq8064 supplies
Srinivas Kandagatla [Thu, 15 Feb 2018 13:26:37 +0000 (13:26 +0000)]
PCI: qcom: Use regulator bulk api for apq8064 supplies

This patch converts existing regulators to use regulator bulk apis,
to make it consistent with msm8996 changes also cut down some redundant code.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Stanimir Varbanov <svarbanov@mm-sol.com>
6 years agoPCI: qcom: Add missing supplies required for msm8996
Srinivas Kandagatla [Thu, 15 Feb 2018 13:22:48 +0000 (13:22 +0000)]
PCI: qcom: Add missing supplies required for msm8996

This patch adds supplies that are required for msm8996. vdda
is analog supply that go in to controller, and vddpe_3v3 is
supply to PCIe endpoint.

Without these supplies PCIe endpoints which require power supplies are
not enumerated at all, as there is no one to power it up.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Stanimir Varbanov <svarbanov@mm-sol.com>
Reviewed-by: Rob Herring <robh@kernel.org>
6 years agoPCI: designware-ep: Fix typo in error message
Niklas Cassel [Thu, 1 Feb 2018 14:02:23 +0000 (15:02 +0100)]
PCI: designware-ep: Fix typo in error message

Fix typo in error message. s/deb_base2/dbi_base2/

Signed-off-by: Niklas Cassel <niklas.cassel@axis.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
6 years agoPCI: dwc: Expand maximum number of MSI IRQs from 32 to 256
Gustavo Pimentel [Tue, 6 Mar 2018 11:54:55 +0000 (11:54 +0000)]
PCI: dwc: Expand maximum number of MSI IRQs from 32 to 256

The Synopsys PCIe Root Complex supports up to MSI 256 IRQs distributed
over 8 controller registers, therefore the maximum number of MSI IRQs
can be changed to 256. The number of controllers can be calculated based
on the number of vectors used by the specific SoC driver.

Update the dwc host bridge driver maximum number of supported MSI
IRQs.

Signed-off-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Tested-by: Niklas Cassel <niklas.cassel@axis.com>
Tested-by: Shawn Guo <shawn.guo@linaro.org>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
6 years agoPCI: dwc: Remove old MSI IRQs API
Gustavo Pimentel [Tue, 6 Mar 2018 11:54:54 +0000 (11:54 +0000)]
PCI: dwc: Remove old MSI IRQs API

Remove the unused old MSI IRQs API from pcie-designware based on
struct msi_controller that should now be considered obsolete.

Signed-off-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Tested-by: Niklas Cassel <niklas.cassel@axis.com>
Tested-by: Shawn Guo <shawn.guo@linaro.org>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
6 years agoPCI: dwc: Move MSI IRQs allocation to IRQ domains hierarchical API
Gustavo Pimentel [Tue, 6 Mar 2018 11:54:53 +0000 (11:54 +0000)]
PCI: dwc: Move MSI IRQs allocation to IRQ domains hierarchical API

Implement a multiplexed IRQ domain hierarchy API in the pcie-designware
host bridge driver that funnels all MSI IRQs into a single parent
interrupt, moving away from the obsolete struct msi_controller based
API.

Although the old implementation API is still available, pcie-designware
will now use the multiplexed IRQ domains hierarchical API.

Remove all existing dwc based host bridges MSI IRQs handlers, in that the
hierarchical API now handles MSI IRQs through the hierarchical/chained
MSI domain implementation.

Signed-off-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Tested-by: Niklas Cassel <niklas.cassel@axis.com>
Tested-by: Shawn Guo <shawn.guo@linaro.org>
Acked-by: Jingoo Han <jingoohan1@gmail.com>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
6 years agoPCI/IOV: Skip INTx config reads for VFs
KarimAllah Ahmed [Wed, 17 Jan 2018 18:30:29 +0000 (19:30 +0100)]
PCI/IOV: Skip INTx config reads for VFs

Per PCIe r4.0, sec 9.2.1.4, VFs can not implement INTX, and their Interrupt
Line and Interrupt Pin registers must be RO Zero.  Some devices have
thousands of VFs, so skip reading the registers as an optimization.

Signed-off-by: KarimAllah Ahmed <karahmed@amazon.de>
Signed-off-by: Jan H. Schönherr <jschoenh@amazon.de>
[bhelgaas: changelog, comment]
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
6 years agoPCI: Wait for device to become ready after secondary bus reset
Sinan Kaya [Tue, 27 Feb 2018 20:14:12 +0000 (14:14 -0600)]
PCI: Wait for device to become ready after secondary bus reset

Setting Secondary Bus Reset of a downstream port sends a hot reset.  PCIe
r4.0, sec 2.3.1, Request Handling Rules, indicates that a device can return
CRS Completion Status following such a reset.  Wait until the device
becomes ready in that situation.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
6 years agoPCI: Add a return type for pci_reset_bridge_secondary_bus()
Sinan Kaya [Tue, 27 Feb 2018 20:14:11 +0000 (14:14 -0600)]
PCI: Add a return type for pci_reset_bridge_secondary_bus()

Add a return value to pci_reset_bridge_secondary_bus() so we can return an
error if the device doesn't become ready after the reset.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
6 years agoPCI: Wait for device to become ready after a power management reset
Sinan Kaya [Tue, 27 Feb 2018 20:14:10 +0000 (14:14 -0600)]
PCI: Wait for device to become ready after a power management reset

PCIe r4.0, sec 2.3.1, Request Handling Rules, indicates that a device can
return CRS Completion Status following a D3hot to D0 transition.  Wait
until the device becomes ready in that situation.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
6 years agoPCI: Fix NULL pointer dereference in of_pci_bus_find_domain_nr()
Shawn Lin [Thu, 1 Mar 2018 01:26:55 +0000 (09:26 +0800)]
PCI: Fix NULL pointer dereference in of_pci_bus_find_domain_nr()

If the "parent" pointer passed to of_pci_bus_find_domain_nr() is NULL,
don't dereference it.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoxtensa/PCI: Use generic pci_mmap_resource_range()
David Woodhouse [Mon, 19 Feb 2018 13:02:33 +0000 (13:02 +0000)]
xtensa/PCI: Use generic pci_mmap_resource_range()

Commit f719582435 ("PCI: Add pci_mmap_resource_range() and use it for
ARM64") added this generic function with the intent of using it everywhere
and ultimately killing the old arch-specific implementations.

Remove the xtensa-specific pci_mmap_page_range() and use the generic
pci_mmap_resource_range() instead.

Xtensa can mmap I/O port space, so supply the xtensa-specific
pci_iobar_pfn() required to make that work.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
[bhelgaas: changelog]
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
Acked-by: Max Filippov <jcmvbkbc@gmail.com>
6 years agopowerpc/pci: Use generic pci_mmap_resource_range()
David Woodhouse [Mon, 19 Feb 2018 12:59:51 +0000 (12:59 +0000)]
powerpc/pci: Use generic pci_mmap_resource_range()

Commit f719582435 ("PCI: Add pci_mmap_resource_range() and use it for
ARM64") added this generic function with the intent of using it everywhere
and ultimately killing the old arch-specific implementations.

Remove the powerpc-specific pci_mmap_page_range() and use the generic
pci_mmap_resource_range() instead.

Powerpc can mmap I/O port space, so supply the powerpc-specific
pci_iobar_pfn() required to make that work.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
[bhelgaas: changelog]
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
6 years agoPCI/ASPM: Don't warn if already in common clock mode
Sinan Kaya [Mon, 22 Jan 2018 20:12:01 +0000 (15:12 -0500)]
PCI/ASPM: Don't warn if already in common clock mode

Previously we emitted a warning if we tried to configure common clock mode
the link was already configured to common clock mode by the UEFI BIOS.
Bail out silently in that case instead of emitting the warning:

  pci 0004:00:00.0: ASPM: Could not configure common clock

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
[bhelgaas: changelog]
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
6 years agoPCI/ASPM: Declare threshold_ns as u32, not u64
Gustavo A. R. Silva [Tue, 27 Feb 2018 23:19:52 +0000 (17:19 -0600)]
PCI/ASPM: Declare threshold_ns as u32, not u64

aspm_calc_l1ss_info() computes l1_2_threshold in microseconds as:

  l1_2_threshold = 2 + 4 + t_common_mode + t_power_on;

where t_common_mode is at most 255us:

  PCI_L1SS_CAP_CM_RESTORE_TIME  0x0000ff00   <-- 8 bits; <256us

and t_power_on is at most 31 * 100us = 3100us:

  PCI_L1SS_CAP_P_PWR_ON_VALUE   0x00f80000   <-- 5 bits; <32
  PCI_L1SS_CAP_P_PWR_ON_SCALE   0x00030000   <-- *2us, *10us, or *100us

So l1_2_threshold is at most 2 + 4 + 255 + 3100 = 3361, which means
threshold_ns is at most 3361 * 1000 = 3361000, which easily fits in a
u32.

Declare threshold_ns as u32, not u64.  This fixes a Coverity warning.

Addresses-Coverity-ID: 1462501
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
[bhelgaas: changelog]
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
6 years agoPCI: cpqphp: Fix possible NULL pointer dereference
Shawn Lin [Sun, 25 Feb 2018 02:01:42 +0000 (10:01 +0800)]
PCI: cpqphp: Fix possible NULL pointer dereference

Check io_node for NULL before dereferencing it.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
6 years agoPCI: altera: Fix bool initialization in tlp_read_packet()
Gustavo A. R. Silva [Sat, 20 Jan 2018 03:26:51 +0000 (21:26 -0600)]
PCI: altera: Fix bool initialization in tlp_read_packet()

Bool variables should be initialized only through true and false
values; update tlp_read_packet() code to comply.

Detected using the Coccinelle tool.

Fixes: eaa6111b70a7 ("PCI: altera: Add Altera PCIe host controller driver")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
[lorenzo.pieralisi@arm.com: updated commit log]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Ley Foon Tan <ley.foon.tan@intel.com>
6 years agoPCI: Rename pci_flr_wait() to pci_dev_wait() and make it generic
Sinan Kaya [Tue, 27 Feb 2018 20:14:10 +0000 (14:14 -0600)]
PCI: Rename pci_flr_wait() to pci_dev_wait() and make it generic

PCIe r4.0, sec 2.3.1, Request Handling Rules, says:

  Valid reset conditions after which a device is permitted to return CRS
  are:
  * Cold, Warm, and Hot Resets,
  * FLR
  * A reset initiated in response to a D3hot to D0 uninitialized

Try to reuse FLR implementation towards other reset types.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
6 years agoPCI: Handle FLR failure and allow other reset types
Sinan Kaya [Tue, 27 Feb 2018 20:14:08 +0000 (14:14 -0600)]
PCI: Handle FLR failure and allow other reset types

pci_flr_wait() and pci_af_flr() functions assume graceful return even
though the device is inaccessible under error conditions.

Return -ENOTTY in error cases so that __pci_reset_function_locked() can
try other reset types if AF_FLR/FLR reset fails.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
6 years agoPCI: Protect restore with device lock to be consistent
Sinan Kaya [Tue, 27 Feb 2018 20:14:08 +0000 (14:14 -0600)]
PCI: Protect restore with device lock to be consistent

Commit b014e96d1abb ("PCI: Protect pci_error_handlers->reset_notify() usage
with device_lock()") added protection around pci_dev_restore() function so
a device-specific remove callback does not cause a race condition with
hotplug.

pci_dev_lock() usage has been forgotten in two places.  Add locks for
pci_slot_restore() and moving pci_dev_restore() inside the locks for
pci_try_reset_function().

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
6 years agoPCI: Add function 1 DMA alias quirk for Marvell 88SE9220
Thomas Vincent-Cross [Tue, 27 Feb 2018 09:20:36 +0000 (20:20 +1100)]
PCI: Add function 1 DMA alias quirk for Marvell 88SE9220

Add Marvell 88SE9220 DMA quirk as found and tested on bug 42679.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=42679
Signed-off-by: Thomas Vincent-Cross <me@tvc.id.au>
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
6 years agoPCI: Add ACS quirk for Ampere root ports
Feng Kan [Wed, 21 Feb 2018 03:19:27 +0000 (19:19 -0800)]
PCI: Add ACS quirk for Ampere root ports

The Ampere Computing PCIe root port does not support ACS at this point.
However, the hardware provides isolation and source validation through the
SMMU. The stream ID generated by the PCIe ports contain both the
bus/device/function number as well as the port ID in its 3 most significant
bits. Turn on ACS but disable all the peer-to-peer features.

APM is being rebranded to Ampere.  The Vendor and Device IDs change, but
the functionality stays the same.

Signed-off-by: Feng Kan <fkan@apm.com>
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
6 years agoPCI/portdrv: Move pcieport_if.h to drivers/pci/pcie/
Frederick Lawler [Wed, 14 Feb 2018 03:52:18 +0000 (21:52 -0600)]
PCI/portdrv: Move pcieport_if.h to drivers/pci/pcie/

Move pcieport_if.h from include/linux to drivers/pci/pcie/pcieport_if.h
because the interfaces there are only used by the PCI core.

Replace all uses of #include<linux/pcieport_if.h> with relative paths to
the new file location, e.g., #include "../pcieport_if.h"

Signed-off-by: Frederick Lawler <fred@fredlawl.com>
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
6 years agoPCI/AER: Move pci_uevent_ers() out of pci.h
Michael Ellerman [Thu, 8 Feb 2018 12:20:35 +0000 (23:20 +1100)]
PCI/AER: Move pci_uevent_ers() out of pci.h

There's no reason pci_uevent_ers() needs to be inline in pci.h, so move it
out to a C file.

Given it's used by AER the obvious location would be somewhere in
drivers/pci/pcie/aer, but because it's also used by powerpc EEH code
unfortunately that doesn't work in the case where EEH is enabled but
PCIEPORTBUS is not.

So for now put it in pci-driver.c, next to pci_uevent(), with an
appropriate #ifdef so it's not built if AER and EEH are both disabled.

While we're moving it also fix up the kernel doc comment for @pdev to be
accurate.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
Reviewed-by: Bryant G. Ly <bryantly@linux.vnet.ibm.com>
6 years agoPCI: Remove redundant probes for device reset support
Bjorn Helgaas [Fri, 16 Feb 2018 21:22:39 +0000 (15:22 -0600)]
PCI: Remove redundant probes for device reset support

We probe every device for whether it supports reset so we can tell whether
to create a sysfs "reset" file for it.  We do that probe in
pci_init_capabilities() during enumeration and save the result in
dev->reset_fn.  The result doesn't depend on any other devices on the bus
and shouldn't change after boot, so we don't need to do the probe again.

Remove the pci_probe_reset_function() calls and rely on the dev->reset_fn
we found during enumeration.  No functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6 years agoPCI: Probe for device reset support during enumeration
Bjorn Helgaas [Fri, 16 Feb 2018 16:55:38 +0000 (10:55 -0600)]
PCI: Probe for device reset support during enumeration

Previously we called pci_probe_reset_function() in this path:

  pci_sysfs_init                              # late_initcall
    for_each_pci_dev(dev)
      pci_create_sysfs_dev_files(dev)
        pci_create_capabilities_sysfs(dev)
          pci_probe_reset_function
            pci_dev_specific_reset
            pcie_has_flr
              pcie_capability_read_dword

pci_sysfs_init() is a late_initcall, and a driver may have already claimed
one of these devices and enabled runtime power management for it, so the
device could already be in D3 by the time we get to pci_sysfs_init().

The device itself should respond to the config read even while it's in
D3hot, but if an upstream bridge is also in D3hot, the read won't even
reach the device because the bridge won't forward it downstream to the
device.  If the bridge is a PCIe port, it should complete the read as an
Unsupported Request, which may be reported to the CPU as an exception or as
invalid data.

Avoid this case by probing for reset support from pci_init_capabilities(),
before a driver can claim the device.  The device may be in D3hot, but any
bridges leading to it should be in D0, so the device's config space should
be fully accessible at that point.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6 years agoPCI: Remove pci_get_bus_and_slot() function
Sinan Kaya [Tue, 19 Dec 2017 05:38:02 +0000 (00:38 -0500)]
PCI: Remove pci_get_bus_and_slot() function

pci_get_bus_and_slot() is restrictive such that it assumes domain=0 as
where a PCI device is present. This restricts the device drivers to be
reused for other domain numbers.

Now that all users of pci_get_bus_and_slot() switched to
pci_get_domain_bus_and_slot(), it is now safe to remove this function.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
6 years agodrm/i915: Deprecate pci_get_bus_and_slot()
Sinan Kaya [Mon, 27 Nov 2017 16:57:46 +0000 (11:57 -0500)]
drm/i915: Deprecate pci_get_bus_and_slot()

pci_get_bus_and_slot() is restrictive such that it assumes domain=0 as
where a PCI device is present. This restricts the device drivers to be
reused for other domain numbers.

Getting ready to remove pci_get_bus_and_slot() function in favor of
pci_get_domain_bus_and_slot().

Extract the domain number from drm_device and pass it into
pci_get_domain_bus_and_slot() function.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
Signed-off-by: Bjorn Helgaas <helgaas@kernel.org>
6 years agorapidio/tsi721: use PCI_EXP_DEVCTL2_COMP_TIMEOUT macro
Bjorn Helgaas [Fri, 15 Dec 2017 22:15:12 +0000 (16:15 -0600)]
rapidio/tsi721: use PCI_EXP_DEVCTL2_COMP_TIMEOUT macro

Use the existing PCI_EXP_DEVCTL2_COMP_TIMEOUT macro instead of hard-coding
the PCIe Completion Timeout Value mask.  No functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Alexandre Bounine <alexandre.bounine@idt.com>