1. 07 10月, 2021 10 次提交
    • P
      PCI: aardvark: Fix link training · f76b36d4
      Pali Rohár 提交于
      Fix multiple link training issues in aardvark driver. The main reason of
      these issues was misunderstanding of what certain registers do, since their
      names and comments were misleading: before commit 96be36db ("PCI:
      aardvark: Replace custom macros by standard linux/pci_regs.h macros"), the
      pci-aardvark.c driver used custom macros for accessing standard PCIe Root
      Bridge registers, and misleading comments did not help to understand what
      the code was really doing.
      
      After doing more tests and experiments I've come to the conclusion that the
      SPEED_GEN register in aardvark sets the PCIe revision / generation
      compliance and forces maximal link speed. Both GEN3 and GEN2 values set the
      read-only PCI_EXP_FLAGS_VERS bits (PCIe capabilities version of Root
      Bridge) to value 2, while GEN1 value sets PCI_EXP_FLAGS_VERS to 1, which
      matches with PCI Express specifications revisions 3, 2 and 1 respectively.
      Changing SPEED_GEN also sets the read-only bits PCI_EXP_LNKCAP_SLS and
      PCI_EXP_LNKCAP2_SLS to corresponding speed.
      
      (Note that PCI Express rev 1 specification does not define PCI_EXP_LNKCAP2
       and PCI_EXP_LNKCTL2 registers and when SPEED_GEN is set to GEN1 (which
       also sets PCI_EXP_FLAGS_VERS set to 1), lspci cannot access
       PCI_EXP_LNKCAP2 and PCI_EXP_LNKCTL2 registers.)
      
      Changing PCIe link speed can be done via PCI_EXP_LNKCTL2_TLS bits of
      PCI_EXP_LNKCTL2 register. Armada 3700 Functional Specifications says that
      the default value of PCI_EXP_LNKCTL2_TLS is based on SPEED_GEN value, but
      tests showed that the default value is always 8.0 GT/s, independently of
      speed set by SPEED_GEN. So after setting SPEED_GEN, we must also set value
      in PCI_EXP_LNKCTL2 register via PCI_EXP_LNKCTL2_TLS bits.
      
      Triggering PCI_EXP_LNKCTL_RL bit immediately after setting LINK_TRAINING_EN
      bit actually doesn't do anything. Tests have shown that a delay is needed
      after enabling LINK_TRAINING_EN bit. As triggering PCI_EXP_LNKCTL_RL
      currently does nothing, remove it.
      
      Commit 43fc679c ("PCI: aardvark: Improve link training") introduced
      code which sets SPEED_GEN register based on negotiated link speed from
      PCI_EXP_LNKSTA_CLS bits of PCI_EXP_LNKSTA register. This code was added to
      fix detection of Compex WLE900VX (Atheros QCA9880) WiFi GEN1 PCIe cards, as
      otherwise these cards were "invisible" on PCIe bus (probably because they
      crashed). But apparently more people reported the same issues with these
      cards also with other PCIe controllers [1] and I was able to reproduce this
      issue also with other "noname" WiFi cards based on Atheros QCA9890 chip
      (with the same PCI vendor/device ids as Atheros QCA9880). So this is not an
      issue in aardvark but rather an issue in Atheros QCA98xx chips. Also, this
      issue only exists if the kernel is compiled with PCIe ASPM support, and a
      generic workaround for this is to change PCIe Bridge to 2.5 GT/s link speed
      via PCI_EXP_LNKCTL2_TLS_2_5GT bits in PCI_EXP_LNKCTL2 register [2], before
      triggering PCI_EXP_LNKCTL_RL bit. This workaround also works when SPEED_GEN
      is set to value GEN2 (5 GT/s). So remove this hack completely in the
      aardvark driver and always set SPEED_GEN to value from 'max-link-speed' DT
      property. Fix for Atheros QCA98xx chips is handled separately by patch [2].
      
      These two things (code for triggering PCI_EXP_LNKCTL_RL bit and changing
      SPEED_GEN value) also explain why commit 69644945 ("PCI: aardvark:
      Train link immediately after enabling training") somehow fixed detection of
      those problematic Compex cards with Atheros chips: if triggering link
      retraining (via PCI_EXP_LNKCTL_RL bit) was done immediately after enabling
      link training (via LINK_TRAINING_EN), it did nothing. If there was a
      specific delay, aardvark HW already initialized PCIe link and therefore
      triggering link retraining caused the above issue. Compex cards triggered
      link down event and disappeared from the PCIe bus.
      
      Commit f4c7d053 ("PCI: aardvark: Wait for endpoint to be ready before
      training link") added 100ms sleep before calling 'Start link training'
      command and explained that it is a requirement of PCI Express
      specification. But the code after this 100ms sleep was not doing 'Start
      link training', rather it triggered PCI_EXP_LNKCTL_RL bit via PCIe Root
      Bridge to put link into Recovery state.
      
      The required delay after fundamental reset is already done in function
      advk_pcie_wait_for_link() which also checks whether PCIe link is up.
      So after removing the code which triggers PCI_EXP_LNKCTL_RL bit on PCIe
      Root Bridge, there is no need to wait 100ms again. Remove the extra
      msleep() call and update comment about the delay required by the PCI
      Express specification.
      
      According to Marvell Armada 3700 Functional Specifications, Link training
      should be enabled via aardvark register LINK_TRAINING_EN after selecting
      PCIe generation and x1 lane. There is no need to disable it prior resetting
      card via PERST# signal. This disabling code was introduced in commit
      5169a985 ("PCI: aardvark: Issue PERST via GPIO") as a workaround for
      some Atheros cards. It turns out that this also is Atheros specific issue
      and affects any PCIe controller, not only aardvark. Moreover this Atheros
      issue was triggered by juggling with PCI_EXP_LNKCTL_RL, LINK_TRAINING_EN
      and SPEED_GEN bits interleaved with sleeps. Now, after removing triggering
      PCI_EXP_LNKCTL_RL, there is no need to explicitly disable LINK_TRAINING_EN
      bit. So remove this code too. The problematic Compex cards described in
      previous git commits are correctly detected in advk_pcie_train_link()
      function even after applying all these changes.
      
      Note that with this patch, and also prior this patch, some NVMe disks which
      support PCIe GEN3 with 8 GT/s speed are negotiated only at the lowest link
      speed 2.5 GT/s, independently of SPEED_GEN value. After manually triggering
      PCI_EXP_LNKCTL_RL bit (e.g. from userspace via setpci), these NVMe disks
      change link speed to 5 GT/s when SPEED_GEN was configured to GEN2. This
      issue first needs to be properly investigated. I will send a fix in the
      future.
      
      On the other hand, some other GEN2 PCIe cards with 5 GT/s speed are
      autonomously by HW autonegotiated at full 5 GT/s speed without need of any
      software interaction.
      
      Armada 3700 Functional Specifications describes the following steps for
      link training: set SPEED_GEN to GEN2, enable LINK_TRAINING_EN, poll until
      link training is complete, trigger PCI_EXP_LNKCTL_RL, poll until signal
      rate is 5 GT/s, poll until link training is complete, enable ASPM L0s.
      
      The requirement for triggering PCI_EXP_LNKCTL_RL can be explained by the
      need to achieve 5 GT/s speed (as changing link speed is done by throw to
      recovery state entered by PCI_EXP_LNKCTL_RL) or maybe as a part of enabling
      ASPM L0s (but in this case ASPM L0s should have been enabled prior
      PCI_EXP_LNKCTL_RL).
      
      It is unknown why the original pci-aardvark.c driver was triggering
      PCI_EXP_LNKCTL_RL bit before waiting for the link to be up. This does not
      align with neither PCIe base specifications nor with Armada 3700 Functional
      Specification. (Note that in older versions of aardvark, this bit was
      called incorrectly PCIE_CORE_LINK_TRAINING, so this may be the reason.)
      
      It is also unknown why Armada 3700 Functional Specification says that it is
      needed to trigger PCI_EXP_LNKCTL_RL for GEN2 mode, as according to PCIe
      base specification 5 GT/s speed negotiation is supposed to be entirely
      autonomous, even if initial speed is 2.5 GT/s.
      
      [1] - https://lore.kernel.org/linux-pci/87h7l8axqp.fsf@toke.dk/
      [2] - https://lore.kernel.org/linux-pci/20210326124326.21163-1-pali@kernel.org/
      
      Link: https://lore.kernel.org/r/20211005180952.6812-12-kabel@kernel.orgSigned-off-by: NPali Rohár <pali@kernel.org>
      Signed-off-by: NMarek Behún <kabel@kernel.org>
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: NMarek Behún <kabel@kernel.org>
      f76b36d4
    • P
      PCI: aardvark: Simplify initialization of rootcap on virtual bridge · 454c5327
      Pali Rohár 提交于
      PCIe config space can be initialized also before pci_bridge_emul_init()
      call, so move rootcap initialization after PCI config space initialization.
      
      This simplifies the function a little since it removes one if (ret < 0)
      check.
      
      Link: https://lore.kernel.org/r/20211005180952.6812-11-kabel@kernel.orgSigned-off-by: NPali Rohár <pali@kernel.org>
      Signed-off-by: NMarek Behún <kabel@kernel.org>
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: NMarek Behún <kabel@kernel.org>
      454c5327
    • P
      PCI: aardvark: Implement re-issuing config requests on CRS response · 223dec14
      Pali Rohár 提交于
      Commit 43f5c77b ("PCI: aardvark: Fix reporting CRS value") fixed
      handling of CRS response and when CRSSVE flag was not enabled it marked CRS
      response as failed transaction (due to simplicity).
      
      But pci-aardvark.c driver is already waiting up to the PIO_RETRY_CNT count
      for PIO config response and so we can with a small change implement
      re-issuing of config requests as described in PCIe base specification.
      
      This change implements re-issuing of config requests when response is CRS.
      Set upper bound of wait cycles to around PIO_RETRY_CNT, afterwards the
      transaction is marked as failed and an all-ones value is returned as
      before.
      
      We do this by returning appropriate error codes from function
      advk_pcie_check_pio_status(). On CRS we return -EAGAIN and caller then
      reissues transaction.
      
      Link: https://lore.kernel.org/r/20211005180952.6812-10-kabel@kernel.orgSigned-off-by: NPali Rohár <pali@kernel.org>
      Signed-off-by: NMarek Behún <kabel@kernel.org>
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: NMarek Behún <kabel@kernel.org>
      223dec14
    • M
      PCI: aardvark: Deduplicate code in advk_pcie_rd_conf() · 67cb2a4c
      Marek Behún 提交于
      Avoid code repetition in advk_pcie_rd_conf() by handling errors with
      goto jump, as is customary in kernel.
      
      Link: https://lore.kernel.org/r/20211005180952.6812-9-kabel@kernel.org
      Fixes: 43f5c77b ("PCI: aardvark: Fix reporting CRS value")
      Signed-off-by: NMarek Behún <kabel@kernel.org>
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      67cb2a4c
    • P
      PCI: aardvark: Do not unmask unused interrupts · 1fb95d7d
      Pali Rohár 提交于
      There are lot of undocumented interrupt bits. To prevent unwanted
      spurious interrupts, fix all *_ALL_MASK macros to define all interrupt
      bits, so that driver can properly mask all interrupts, including those
      which are undocumented.
      
      Link: https://lore.kernel.org/r/20211005180952.6812-8-kabel@kernel.org
      Fixes: 8c39d710 ("PCI: aardvark: Add Aardvark PCI host controller driver")
      Signed-off-by: NPali Rohár <pali@kernel.org>
      Signed-off-by: NMarek Behún <kabel@kernel.org>
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: NMarek Behún <kabel@kernel.org>
      Cc: stable@vger.kernel.org
      1fb95d7d
    • P
      PCI: aardvark: Do not clear status bits of masked interrupts · a7ca6d7f
      Pali Rohár 提交于
      The PCIE_ISR1_REG says which interrupts are currently set / active,
      including those which are masked.
      
      The driver currently reads this register and looks if some unmasked
      interrupts are active, and if not, it clears status bits of _all_
      interrupts, including the masked ones.
      
      This is incorrect, since, for example, some drivers may poll these bits.
      
      Remove this clearing, and also remove this early return statement
      completely, since it does not change functionality in any way.
      
      Link: https://lore.kernel.org/r/20211005180952.6812-7-kabel@kernel.org
      Fixes: 8c39d710 ("PCI: aardvark: Add Aardvark PCI host controller driver")
      Signed-off-by: NPali Rohár <pali@kernel.org>
      Signed-off-by: NMarek Behún <kabel@kernel.org>
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: NMarek Behún <kabel@kernel.org>
      Cc: stable@vger.kernel.org
      a7ca6d7f
    • P
      PCI: aardvark: Fix configuring Reference clock · 46ef6090
      Pali Rohár 提交于
      Commit 36669701 ("PCI: aardvark: Add PHY support") introduced
      configuration of PCIe Reference clock via PCIE_CORE_REF_CLK_REG register,
      but did it incorrectly.
      
      PCIe Reference clock differential pair is routed from system board to
      endpoint card, so on CPU side it has output direction. Therefore it is
      required to enable transmitting and disable receiving.
      
      Default configuration according to Armada 3700 Functional Specifications is
      enabled receiver part and disabled transmitter.
      
      We need this change because otherwise PCIe Reference clock is configured to
      some undefined state when differential pair is used for both transmitting
      and receiving.
      
      Fix this by disabling receiver part.
      
      Link: https://lore.kernel.org/r/20211005180952.6812-6-kabel@kernel.org
      Fixes: 36669701 ("PCI: aardvark: Add PHY support")
      Signed-off-by: NPali Rohár <pali@kernel.org>
      Signed-off-by: NMarek Behún <kabel@kernel.org>
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: NMarek Behún <kabel@kernel.org>
      Cc: stable@vger.kernel.org
      46ef6090
    • P
      PCI: aardvark: Fix preserving PCI_EXP_RTCTL_CRSSVE flag on emulated bridge · d419052b
      Pali Rohár 提交于
      Commit 43f5c77b ("PCI: aardvark: Fix reporting CRS value") started
      using CRSSVE flag for handling CRS responses.
      
      PCI_EXP_RTCTL_CRSSVE flag is stored only in emulated config space buffer
      and there is handler for PCI_EXP_RTCTL register. So every read operation
      from config space automatically clears CRSSVE flag as it is not defined in
      PCI_EXP_RTCTL read handler.
      
      Fix this by reading current CRSSVE bit flag from emulated space buffer and
      appending it to PCI_EXP_RTCTL read response.
      
      Link: https://lore.kernel.org/r/20211005180952.6812-5-kabel@kernel.org
      Fixes: 43f5c77b ("PCI: aardvark: Fix reporting CRS value")
      Signed-off-by: NPali Rohár <pali@kernel.org>
      Signed-off-by: NMarek Behún <kabel@kernel.org>
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: NMarek Behún <kabel@kernel.org>
      d419052b
    • M
      PCI: aardvark: Don't spam about PIO Response Status · 464de7e7
      Marek Behún 提交于
      Use dev_dbg() instead of dev_err() in advk_pcie_check_pio_status().
      
      For example CRS is not an error status, it just says that the request
      should be retried.
      
      Link: https://lore.kernel.org/r/20211005180952.6812-4-kabel@kernel.org
      Fixes: 8c39d710 ("PCI: aardvark: Add Aardvark PCI host controller driver")
      Signed-off-by: NMarek Behún <kabel@kernel.org>
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      464de7e7
    • P
      PCI: aardvark: Fix PCIe Max Payload Size setting · a4e17d65
      Pali Rohár 提交于
      Change PCIe Max Payload Size setting in PCIe Device Control register to 512
      bytes to align with PCIe Link Initialization sequence as defined in Marvell
      Armada 3700 Functional Specification. According to the specification,
      maximal Max Payload Size supported by this device is 512 bytes.
      
      Without this kernel prints suspicious line:
      
          pci 0000:01:00.0: Upstream bridge's Max Payload Size set to 256 (was 16384, max 512)
      
      With this change it changes to:
      
          pci 0000:01:00.0: Upstream bridge's Max Payload Size set to 256 (was 512, max 512)
      
      Link: https://lore.kernel.org/r/20211005180952.6812-3-kabel@kernel.org
      Fixes: 8c39d710 ("PCI: aardvark: Add Aardvark PCI host controller driver")
      Signed-off-by: NPali Rohár <pali@kernel.org>
      Signed-off-by: NMarek Behún <kabel@kernel.org>
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: NMarek Behún <kabel@kernel.org>
      Cc: stable@vger.kernel.org
      a4e17d65
  2. 26 8月, 2021 1 次提交
  3. 20 8月, 2021 1 次提交
    • P
      PCI: aardvark: Configure PCIe resources from 'ranges' DT property · 64f160e1
      Pali Rohár 提交于
      In commit 6df6ba97 ("PCI: aardvark: Remove PCIe outbound window
      configuration") was removed aardvark PCIe outbound window configuration and
      commit description said that was recommended solution by HW designers.
      
      But that commit completely removed support for configuring PCIe IO
      resources without removing PCIe IO 'ranges' from DTS files. After that
      commit PCIe IO space started to be treated as PCIe MEM space and accessing
      it just caused kernel crash.
      
      Moreover implementation of PCIe outbound windows prior that commit was
      incorrect. It completely ignored offset between CPU address and PCIe bus
      address and expected that in DTS is CPU address always same as PCIe bus
      address without doing any checks. Also it completely ignored size of every
      PCIe resource specified in 'ranges' DTS property and expected that every
      PCIe resource has size 128 MB (also for PCIe IO range). Again without any
      check. Apparently none of PCIe resource has in DTS specified size of 128
      MB. So it was completely broken and thanks to how aardvark mask works,
      configuration was completely ignored.
      
      This patch reverts back support for PCIe outbound window configuration but
      implementation is a new without issues mentioned above. PCIe outbound
      window is required when DTS specify in 'ranges' property non-zero offset
      between CPU and PCIe address space. To address recommendation by HW
      designers as specified in commit description of 6df6ba97, set default
      outbound parameters as PCIe MEM access without translation and therefore
      for this PCIe 'ranges' it is not needed to configure PCIe outbound window.
      For PCIe IO space is needed to configure aardvark PCIe outbound window.
      
      This patch fixes kernel crash when trying to access PCIe IO space.
      
      Link: https://lore.kernel.org/r/20210624215546.4015-2-pali@kernel.orgSigned-off-by: NPali Rohár <pali@kernel.org>
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Cc: stable@vger.kernel.org # 6df6ba97 ("PCI: aardvark: Remove PCIe outbound window configuration")
      64f160e1
  4. 05 8月, 2021 3 次提交
  5. 03 8月, 2021 1 次提交
  6. 25 6月, 2021 2 次提交
  7. 18 6月, 2021 1 次提交
  8. 11 12月, 2020 1 次提交
  9. 08 12月, 2020 1 次提交
  10. 02 10月, 2020 1 次提交
  11. 07 9月, 2020 4 次提交
  12. 04 8月, 2020 2 次提交
  13. 24 7月, 2020 1 次提交
    • R
      PCI: Move setting pci_host_bridge.busnr out of host drivers · 4f5c883d
      Rob Herring 提交于
      Most host drivers only parse the DT bus range to set the root bus number
      in pci_host_bridge.busnr. The ones that don't set busnr are buggy in
      that they ignore what's in DT. Let's set busnr in pci_scan_root_bus_bridge()
      where we already check for the bus resource and remove setting it in
      host drivers.
      
      Link: https://lore.kernel.org/r/20200722022514.1283916-12-robh@kernel.orgSigned-off-by: NRob Herring <robh@kernel.org>
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Acked-by: NBjorn Helgaas <bhelgaas@google.com>
      Cc: Jingoo Han <jingoohan1@gmail.com>
      Cc: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
      Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Cc: Bjorn Helgaas <bhelgaas@google.com>
      Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Thierry Reding <thierry.reding@gmail.com>
      Cc: Jonathan Hunter <jonathanh@nvidia.com>
      Cc: Linus Walleij <linus.walleij@linaro.org>
      Cc: Ryder Lee <ryder.lee@mediatek.com>
      Cc: Marek Vasut <marek.vasut+renesas@gmail.com>
      Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
      Cc: linux-tegra@vger.kernel.org
      Cc: linux-mediatek@lists.infradead.org
      Cc: linux-renesas-soc@vger.kernel.org
      4f5c883d
  14. 23 7月, 2020 3 次提交
  15. 21 7月, 2020 1 次提交
    • P
      PCI: aardvark: Don't touch PCIe registers if no card connected · 70e38025
      Pali Rohár 提交于
      When there is no PCIe card connected and advk_pcie_rd_conf() or
      advk_pcie_wr_conf() is called for PCI bus which doesn't belong to emulated
      root bridge, the aardvark driver throws the following error message:
      
        advk-pcie d0070000.pcie: config read/write timed out
      
      Obviously accessing PCIe registers of disconnected card is not possible.
      
      Extend check in advk_pcie_valid_device() function for validating
      availability of PCIe bus. If PCIe link is down, then the device is marked
      as Not Found and the driver does not try to access these registers.
      
      This is just an optimization to prevent accessing PCIe registers when card
      is disconnected. Trying to access PCIe registers of disconnected card does
      not cause any crash, kernel just needs to wait for a timeout. So if card
      disappear immediately after checking for PCIe link (before accessing PCIe
      registers), it does not cause any problems.
      
      Link: https://lore.kernel.org/r/20200702083036.12230-1-pali@kernel.orgSigned-off-by: NPali Rohár <pali@kernel.org>
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      70e38025
  16. 10 7月, 2020 1 次提交
  17. 07 7月, 2020 1 次提交
  18. 18 5月, 2020 5 次提交