1. 13 9月, 2014 2 次提交
    • B
      PCI: Add pci_configure_device() during enumeration · 6cd33649
      Bjorn Helgaas 提交于
      Some platforms can tell the OS how to configure PCI devices, e.g., how to
      set cache line size, error reporting enables, etc.  ACPI defines _HPP and
      _HPX methods for this purpose.
      
      This configuration was previously done by some of the hotplug drivers using
      pci_configure_slot().  But not all hotplug drivers did this, and per the
      spec (ACPI rev 5.0, sec 6.2.7), we can also do it for "devices not
      configured by the BIOS at system boot."
      
      Move this configuration into the PCI core by adding pci_configure_device()
      and calling it from pci_device_add(), so we do this for all devices as we
      enumerate them.
      
      This is based on pci_configure_slot(), which is used by hotplug drivers.
      I omitted:
      
        - pcie_bus_configure_settings() because it configures MPS and MRRS, which
          requires global knowledge of the fabric and must be done later, and
      
        - configuration of subordinate devices; that will happen when we call
          pci_device_add() for those devices.
      
      Because pci_configure_slot() was only done by hotplug drivers, this initial
      version of pci_configure_device() only configures hot-added devices,
      ignoring anything added during boot.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Acked-by: NYinghai Lu <yinghai@kernel.org>
      6cd33649
    • B
      PCI: Move pci_configure_slot() to drivers/pci/probe.c · 589fcc23
      Bjorn Helgaas 提交于
      Move pci_configure_slot() and related functions from
      drivers/pci/hotplug/pcihp_slot to drivers/pci/probe.c.
      
      This is to prepare for doing device configuration during the normal
      enumeration process instead of just after hot-add.
      
      No functional change.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      589fcc23
  2. 11 6月, 2014 3 次提交
  3. 29 5月, 2014 1 次提交
    • A
      PCI: Introduce new device binding path using pci_dev.driver_override · 782a985d
      Alex Williamson 提交于
      The driver_override field allows us to specify the driver for a device
      rather than relying on the driver to provide a positive match of the
      device.  This shortcuts the existing process of looking up the vendor and
      device ID, adding them to the driver new_id, binding the device, then
      removing the ID, but it also provides a couple advantages.
      
      First, the above existing process allows the driver to bind to any device
      matching the new_id for the window where it's enabled.  This is often not
      desired, such as the case of trying to bind a single device to a meta
      driver like pci-stub or vfio-pci.  Using driver_override we can do this
      deterministically using:
      
        echo pci-stub > /sys/bus/pci/devices/0000:03:00.0/driver_override
        echo 0000:03:00.0 > /sys/bus/pci/devices/0000:03:00.0/driver/unbind
        echo 0000:03:00.0 > /sys/bus/pci/drivers_probe
      
      Previously we could not invoke drivers_probe after adding a device to
      new_id for a driver as we get non-deterministic behavior whether the driver
      we intend or the standard driver will claim the device.  Now it becomes a
      deterministic process, only the driver matching driver_override will probe
      the device.
      
      To return the device to the standard driver, we simply clear the
      driver_override and reprobe the device:
      
        echo > /sys/bus/pci/devices/0000:03:00.0/driver_override
        echo 0000:03:00.0 > /sys/bus/pci/devices/0000:03:00.0/driver/unbind
        echo 0000:03:00.0 > /sys/bus/pci/drivers_probe
      
      Another advantage to this approach is that we can specify a driver override
      to force a specific binding or prevent any binding.  For instance when an
      IOMMU group is exposed to userspace through VFIO we require that all
      devices within that group are owned by VFIO.  However, devices can be
      hot-added into an IOMMU group, in which case we want to prevent the device
      from binding to any driver (override driver = "none") or perhaps have it
      automatically bind to vfio-pci.  With driver_override it's a simple matter
      for this field to be set internally when the device is first discovered to
      prevent driver matches.
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
      Reviewed-by: NAlexander Graf <agraf@suse.de>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      782a985d
  4. 28 5月, 2014 2 次提交
    • A
      PCI: Test for std config alias when testing extended config space · 78916b00
      Alex Williamson 提交于
      When a PCI-to-PCIe bridge is stacked on a PCIe-to-PCI bridge, we can have
      PCIe endpoints masked by a conventional PCI bus.  This makes the extended
      config space of the PCIe endpoint inaccessible.  The PCIe-to-PCI bridge is
      supposed to handle any type 1 configuration transactions where the extended
      config offset bits are non-zero as an Unsupported Request rather than
      forward it to the secondary interface.  As noted here, there are a couple
      known offenders to this rule.  These bridges drop the extended offset bits,
      resulting in the conventional config space being aliased many times across
      the extended config space.  For Intel NICs, this alias often seems to
      expose a bogus SR-IOV cap.
      
      Stacking bridges may seem like an uncommon scenario, but note that any
      conventional PCI slot in a modern PC is already the secondary interface of
      an onboard PCIe-to-PCI bridge.  The user need only add a PCI-to-PCIe
      adapter and PCIe device to encounter this problem.
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      78916b00
    • Y
      PCI: Use pci_is_bridge() to simplify code · 6788a51f
      Yijing Wang 提交于
      Use pci_is_bridge() to simplify code.  No functional change.
      
      Requires: 326c1cda PCI: Rename pci_is_bridge() to pci_has_subordinate()
      Requires: 1c86438c PCI: Add new pci_is_bridge() interface
      Signed-off-by: NYijing Wang <wangyijing@huawei.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      6788a51f
  5. 24 5月, 2014 6 次提交
    • B
      PCI: Don't add disabled subtractive decode bus resources · d739a099
      Bjorn Helgaas 提交于
      For a subtractive decode bridge, we previously added and printed all
      resources of the primary bus, even if they were not valid.  In the example
      below, the bridge 00:1c.3 has no windows enabled, so there are no valid
      resources on bus 02.  But since 02:00.0 is subtractive decode bridge, we
      add and print all those invalid resources, which don't really make sense:
      
        pci 0000:00:1c.3: PCI bridge to [bus 02-03]
        pci 0000:02:00.0: PCI bridge to [bus 03] (subtractive decode)
        pci 0000:02:00.0:   bridge window [??? 0x00000000 flags 0x0] (subtractive decode)
      
      Add and print the subtractively-decoded resources only if they are valid.
      
      There's an example in the dmesg log attached to the bugzilla below (but
      this patch doesn't fix the bug reported there).
      
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=73141Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      d739a099
    • B
      PCI: Don't print anything while decoding is disabled · 26370fc6
      Bjorn Helgaas 提交于
      If the console is a PCI device, and we try to print to it while its
      decoding is disabled, the system will hang.  This particular printk hasn't
      caused a problem yet, but it could, so this fixes it.
      
      See also 0ff9514b ("PCI: Don't print anything while decoding is
      disabled").
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      26370fc6
    • B
      PCI: Don't set BAR to zero if dma_addr_t is too small · 31e9dd25
      Bjorn Helgaas 提交于
      If a BAR is above 4GB and our dma_addr_t is too small, don't clear the BAR
      to zero: that doesn't disable the BAR, and it makes it more likely that the
      BAR will conflict with things if we turn on the memory enable bit (as we
      will at "out:" if the device was already enabled at the handoff).
      
      We should also print the BAR info and its original size so we can follow
      the process when we try to assign space to it.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      31e9dd25
    • B
      PCI: Don't convert BAR address to resource if dma_addr_t is too small · 72dc5601
      Bjorn Helgaas 提交于
      If dma_addr_t is too small to represent the BAR value,
      pcibios_bus_to_resource() will fail, so just remember the BAR size directly
      in the resource.  The resource is already marked UNSET, so we know the
      address isn't valid anyway.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      72dc5601
    • B
      PCI: Reject BAR above 4GB if dma_addr_t is too small · d1a313e4
      Bjorn Helgaas 提交于
      We can only handle BARs above 4GB if dma_addr_t (not resource_size_t) is 64
      bits wide.  If we have a 64-bit resource_size_t and a 32-bit dma_addr_t,
      we can't deal with BARs above 4GB.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      d1a313e4
    • B
      PCI: Fail safely if we can't handle BARs larger than 4GB · 23b13bc7
      Bjorn Helgaas 提交于
      We can only handle BARs larger than 4GB if both dma_addr_t and
      resource_size_t are 64 bits wide.  If dma_addr_t is 32 bits, we can't
      represent all the bus addresses, and if resource_size_t is 32 bits, we
      can't represent all the CPU addresses.
      
      Previously we cleared res->flags (at "fail:") for resources that were too
      large.  That means we think the BAR doesn't exist at all, which in turn
      means that we could enable the device even though we can't keep track of
      where the BAR is and we can't make sure it doesn't overlap something else.
      
      This preserves the type flags (MEM/IO) so we can keep from enabling the
      device.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      23b13bc7
  6. 30 4月, 2014 2 次提交
    • B
      PCI: Fix use of uninitialized MPS value · 1e358f94
      Bjorn Helgaas 提交于
      If "pcie_bus_config == PCIE_BUS_PERFORMANCE", we don't initialize "smpss",
      so we pass a pointer to garbage into pcie_bus_configure_set(), where we
      compute "mps" based on the garbage.  We then pass the garbage "mps" to
      pcie_write_mps(), which ignores it in the PCIE_BUS_PERFORMANCE case.
      
      Coverity isn't smart enough to deduce that we ignore the garbage (it's a
      lot to expect from a human, too), so initialize "smpss" to a safe value in
      all cases.
      
      Found by Coverity (CID 146454).
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      1e358f94
    • B
      PCI: Remove unnecessary __ref annotations · 10874f5a
      Bjorn Helgaas 提交于
      Some PCI functions used to be marked __devinit.  When CONFIG_HOTPLUG was
      not set, these functions were discarded after boot.  A few callers of these
      __devinit functions were marked __ref to indicate that they could safely
      call the __devinit functions even though the callers were not __devinit.
      
      But CONFIG_HOTPLUG and __devinit are now gone, and the need for the __ref
      annotations is also gone, so remove them.  Relevant historical commits:
      
        54b956b9 Remove __dev* markings from init.h
        a8e4b9c1 PCI: add generic pci_hp_add_bridge()
        0ab2b57f PCI: fix section mismatch warning in pci_scan_child_bus
        451124a7 PCI: fix 4x section mismatch warnings
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      10874f5a
  7. 20 3月, 2014 1 次提交
  8. 28 2月, 2014 1 次提交
    • B
      PCI: Mark 64-bit resource as IORESOURCE_UNSET if we only support 32-bit · c83bd900
      Bjorn Helgaas 提交于
      If we don't support 64-bit addresses, i.e., CONFIG_PHYS_ADDR_T_64BIT is not
      set, we can't deal with BARs above 4GB.  In this case we already pretend
      the BAR contained zero; this patch also sets IORESOURCE_UNSET so we can try
      to reallocate it later.
      
      I don't think this is exactly correct: what we care about here are *bus*
      addresses, not CPU addresses, so the tests of sizeof(resource_size_t)
      probably should be on sizeof(dma_addr_t) instead.  But this is what's been
      in -next, so we'll fix that later.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      c83bd900
  9. 12 2月, 2014 3 次提交
  10. 11 2月, 2014 5 次提交
  11. 02 2月, 2014 1 次提交
    • R
      Revert "PCI: Remove from bus_list and release resources in pci_release_dev()" · 04480094
      Rafael J. Wysocki 提交于
      Revert commit ef83b078 "PCI: Remove from bus_list and release
      resources in pci_release_dev()" that made some nasty race conditions
      become possible.  For example, if a Thunderbolt link is unplugged
      and then replugged immediately, the pci_release_dev() resulting from
      the hot-remove code path may be racing with the hot-add code path
      which after that commit causes various kinds of breakage to happen
      (up to and including a hard crash of the whole system).
      
      Moreover, the problem that commit ef83b078 attempted to address
      cannot happen any more after commit 8a4c5c32 "PCI: Check parent
      kobject in pci_destroy_dev()", because pci_destroy_dev() will now
      return immediately if it has already been executed for the given
      device.
      
      Note, however, that the invocation of msi_remove_pci_irq_vectors()
      removed by commit ef83b078 from pci_free_resources() along with
      the other changes made by it is not added back because of subsequent
      code changes depending on that modification.
      
      Fixes: ef83b078 (PCI: Remove from bus_list and release resources in pci_release_dev())
      Reported-by: NMika Westerberg <mika.westerberg@linux.intel.com>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      04480094
  12. 14 1月, 2014 3 次提交
    • R
      PCI: Add global pci_lock_rescan_remove() · 9d16947b
      Rafael J. Wysocki 提交于
      There are multiple PCI device addition and removal code paths that may be
      run concurrently with the generic PCI bus rescan and device removal that
      can be triggered via sysfs.  If that happens, it may lead to multiple
      different, potentially dangerous race conditions.
      
      The most straightforward way to address those problems is to run
      the code in question under the same lock that is used by the
      generic rescan/remove code in pci-sysfs.c.  To prepare for those
      changes, move the definition of the global PCI remove/rescan lock
      to probe.c and provide global wrappers, pci_lock_rescan_remove()
      and pci_unlock_rescan_remove(), allowing drivers to manipulate
      that lock.  Also provide pci_stop_and_remove_bus_device_locked()
      for the callers of pci_stop_and_remove_bus_device() who only need
      to hold the rescan/remove lock around it.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      9d16947b
    • S
      PCI: Make local functions static · 0b950f0f
      Stephen Hemminger 提交于
      Using 'make namespacecheck' identify code which should be declared static.
      Checked for users in other driver/archs as well.  Compile tested only.
      
      This stops exporting the following interfaces to modules:
      
          pci_target_state()
          pci_load_saved_state()
      
      [bhelgaas: retained pci_find_next_ext_capability() and pci_cfg_space_size()]
      Signed-off-by: NStephen Hemminger <stephen@networkplumber.org>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      0b950f0f
    • S
      PCI: Remove unused alloc_pci_dev() · e2760c54
      Stephen Hemminger 提交于
      My philosophy is unused code is dead code.  And dead code is subject to bit
      rot and is a likely source of bugs.  Use it or lose it.
      
      This removes this unused and deprecated interface:
      
          alloc_pci_dev()
      
      [bhelgaas: split to separate patch]
      Signed-off-by: NStephen Hemminger <stephen@networkplumber.org>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      e2760c54
  13. 22 12月, 2013 1 次提交
    • Y
      PCI: Convert pcibios_resource_to_bus() to take a pci_bus, not a pci_dev · fc279850
      Yinghai Lu 提交于
      These interfaces:
      
        pcibios_resource_to_bus(struct pci_dev *dev, *bus_region, *resource)
        pcibios_bus_to_resource(struct pci_dev *dev, *resource, *bus_region)
      
      took a pci_dev, but they really depend only on the pci_bus.  And we want to
      use them in resource allocation paths where we have the bus but not a
      device, so this patch converts them to take the pci_bus instead of the
      pci_dev:
      
        pcibios_resource_to_bus(struct pci_bus *bus, *bus_region, *resource)
        pcibios_bus_to_resource(struct pci_bus *bus, *resource, *bus_region)
      
      In fact, with standard PCI-PCI bridges, they only depend on the host
      bridge, because that's the only place address translation occurs, but
      we aren't going that far yet.
      
      [bhelgaas: changelog]
      Signed-off-by: NYinghai Lu <yinghai@kernel.org>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      fc279850
  14. 19 12月, 2013 2 次提交
  15. 15 11月, 2013 1 次提交
  16. 26 9月, 2013 1 次提交
  17. 24 9月, 2013 1 次提交
  18. 27 8月, 2013 2 次提交
  19. 23 8月, 2013 2 次提交
    • Z
      PCI: Disable decoding for BAR sizing only when it was actually enabled · 808e34e2
      Zoltan Kiss 提交于
      We disable BARs while sizing them so we don't cause conflicts with other
      devices (see 253d2e54 and bbffe435).  But if device decoding is already
      disabled before we size the BAR, we don't need to disable it again.
      
      [bhelgaas: changelog, add PCI_COMMAND_DECODING_ENABLE for readability]
      Signed-off-by: NZoltan Kiss <zoltan.kiss@citrix.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      808e34e2
    • Y
      PCI: Don't restrict MPS for slots below Root Ports · d4aa68f6
      Yijing Wang 提交于
      When booting with "pci=pcie_bus_safe", we previously limited the
      fabric MPS to 128 when we found:
      
        (1) A hotplug-capable Downstream Port ("dev->is_hotplug_bridge &&
            pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT"), or
      
        (2) A hotplug-capable Root Port with a slot that was either empty or
            contained a multi-function device ("dev->is_hotplug_bridge &&
            !list_is_singular(&dev->bus->devices)")
      
      Part (1) is valid, but part (2) is not.
      
      After a hot-add in the slot below a Root Port, we can reconfigure all
      MPS values in the fabric below the Root Port because the new device is
      the only thing below the Root Port and there are no active drivers.
      Therefore, there's no reason to limit the MPS for Root Ports, no
      matter what's in the slot.
      
      Test info:
      
          -+-[0000:40]-+-07.0-[0000:46]--+-00.0  Intel 82576 NIC
                                         \-00.1  Intel 82576 NIC
      
          0000:40:07.0 Root Port bridge to [bus 46] (MPS supported=256)
          0000:46:00.0 Endpoint                     (MPS supported=512)
          0000:46:00.1 Endpoint                     (MPS supported=512)
      
          # echo 0 > /sys/bus/pci/slots/7/power
          # echo 1 > /sys/bus/pci/slots/7/power
          pcieport 0000:40:07.0: PCI-E Max Payload Size set to 256/ 256 (was 256)
          pci 0000:46:00.0:      PCI-E Max Payload Size set to 256/ 512 (was 128)
          pci 0000:46:00.1:      PCI-E Max Payload Size set to 256/ 512 (was 128)
      
      Before this change, we set MPS to 128 for the Root Port and both NICs
      because the slot contained a multi-function device and
      
          dev->is_hotplug_bridge && !list_is_singular(&dev->bus->devices)
      
      was true.  After this change, we set it to 256.
      
      [bhelgaas: changelog, comments, split out upstream bridge check]
      Signed-off-by: NYijing Wang <wangyijing@huawei.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Cc: Jon Mason <jdmason@kudzu.us>
      d4aa68f6