1. 29 Oct, 2021 5 commits
  2. 07 Oct, 2021 13 commits
    • Pali Rohár's avatar
      PCI: aardvark: Fix reporting Data Link Layer Link Active · 2b650b7f
      Pali Rohár authored
      Add support for reporting PCI_EXP_LNKSTA_DLLLA bit in Link Control register
      on emulated bridge via current LTSSM state. Also correctly indicate DLLLA
      capability via PCI_EXP_LNKCAP_DLLLARC bit in Link Control Capability
      register.
      
      Link: https://lore.kernel.org/r/20211005180952.6812-14-kabel@kernel.org
      Fixes: 8a3ebd8d ("PCI: aardvark: Implement emulated root PCI bridge config space")
      Signed-off-by: default avatarPali Rohár <pali@kernel.org>
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: default avatarMarek Behún <kabel@kernel.org>
      Cc: stable@vger.kernel.org
      2b650b7f
    • Pali Rohár's avatar
      PCI: aardvark: Fix checking for link up via LTSSM state · 661c399a
      Pali Rohár authored
      Current implementation of advk_pcie_link_up() is wrong as it marks also
      link disabled or hot reset states as link up.
      
      Fix it by marking link up only to those states which are defined in PCIe
      Base specification 3.0, Table 4-14: Link Status Mapped to the LTSSM.
      
      To simplify implementation, Define macros for every LTSSM state which
      aardvark hardware can return in CFG_REG register.
      
      Fix also checking for link training according to the same Table 4-14.
      Define a new function advk_pcie_link_training() for this purpose.
      
      Link: https://lore.kernel.org/r/20211005180952.6812-13-kabel@kernel.org
      Fixes: 8c39d710 ("PCI: aardvark: Add Aardvark PCI host controller driver")
      Signed-off-by: default avatarPali Rohár <pali@kernel.org>
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: default avatarMarek Behún <kabel@kernel.org>
      Cc: stable@vger.kernel.org
      Cc: Remi Pommarel <repk@triplefau.lt>
      661c399a
    • Pali Rohár's avatar
      PCI: aardvark: Fix link training · f76b36d4
      Pali Rohár authored
      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: default avatarPali Rohár <pali@kernel.org>
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: default avatarMarek Behún <kabel@kernel.org>
      f76b36d4
    • Pali Rohár's avatar
      PCI: aardvark: Simplify initialization of rootcap on virtual bridge · 454c5327
      Pali Rohár authored
      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: default avatarPali Rohár <pali@kernel.org>
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: default avatarMarek Behún <kabel@kernel.org>
      454c5327
    • Pali Rohár's avatar
      PCI: aardvark: Implement re-issuing config requests on CRS response · 223dec14
      Pali Rohár authored
      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: default avatarPali Rohár <pali@kernel.org>
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: default avatarMarek Behún <kabel@kernel.org>
      223dec14
    • Marek Behún's avatar
      PCI: aardvark: Deduplicate code in advk_pcie_rd_conf() · 67cb2a4c
      Marek Behún authored
      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: default avatarMarek Behún <kabel@kernel.org>
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      67cb2a4c
    • Pali Rohár's avatar
      PCI: aardvark: Do not unmask unused interrupts · 1fb95d7d
      Pali Rohár authored
      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: default avatarPali Rohár <pali@kernel.org>
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: default avatarMarek Behún <kabel@kernel.org>
      Cc: stable@vger.kernel.org
      1fb95d7d
    • Pali Rohár's avatar
      PCI: aardvark: Do not clear status bits of masked interrupts · a7ca6d7f
      Pali Rohár authored
      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: default avatarPali Rohár <pali@kernel.org>
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: default avatarMarek Behún <kabel@kernel.org>
      Cc: stable@vger.kernel.org
      a7ca6d7f
    • Pali Rohár's avatar
      PCI: aardvark: Fix configuring Reference clock · 46ef6090
      Pali Rohár authored
      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: default avatarPali Rohár <pali@kernel.org>
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: default avatarMarek Behún <kabel@kernel.org>
      Cc: stable@vger.kernel.org
      46ef6090
    • Pali Rohár's avatar
      PCI: aardvark: Fix preserving PCI_EXP_RTCTL_CRSSVE flag on emulated bridge · d419052b
      Pali Rohár authored
      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: default avatarPali Rohár <pali@kernel.org>
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: default avatarMarek Behún <kabel@kernel.org>
      d419052b
    • Marek Behún's avatar
      PCI: aardvark: Don't spam about PIO Response Status · 464de7e7
      Marek Behún authored
      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: default avatarMarek Behún <kabel@kernel.org>
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      464de7e7
    • Pali Rohár's avatar
      PCI: aardvark: Fix PCIe Max Payload Size setting · a4e17d65
      Pali Rohár authored
      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: default avatarPali Rohár <pali@kernel.org>
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: default avatarMarek Behún <kabel@kernel.org>
      Cc: stable@vger.kernel.org
      a4e17d65
    • Pali Rohár's avatar
      PCI: Add PCI_EXP_DEVCTL_PAYLOAD_* macros · 460275f1
      Pali Rohár authored
      Define a macro PCI_EXP_DEVCTL_PAYLOAD_* for every possible Max Payload
      Size in linux/pci_regs.h, in the same style as PCI_EXP_DEVCTL_READRQ_*.
      
      Link: https://lore.kernel.org/r/20211005180952.6812-2-kabel@kernel.orgSigned-off-by: default avatarPali Rohár <pali@kernel.org>
      Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: default avatarMarek Behún <kabel@kernel.org>
      Reviewed-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      460275f1
  3. 20 Sep, 2021 2 commits
    • Linus Torvalds's avatar
      Linux 5.15-rc2 · e4e737bb
      Linus Torvalds authored
      e4e737bb
    • Linus Torvalds's avatar
      pci_iounmap'2: Electric Boogaloo: try to make sense of it all · 316e8d79
      Linus Torvalds authored
      Nathan Chancellor reports that the recent change to pci_iounmap in
      commit 9caea000 ("parisc: Declare pci_iounmap() parisc version only
      when CONFIG_PCI enabled") causes build errors on arm64.
      
      It took me about two hours to convince myself that I think I know what
      the logic of that mess of #ifdef's in the <asm-generic/io.h> header file
      really aim to do, and rewrite it to be easier to follow.
      
      Famous last words.
      
      Anyway, the code has now been lifted from that grotty header file into
      lib/pci_iomap.c, and has fairly extensive comments about what the logic
      is.  It also avoids indirecting through another confusing (and badly
      named) helper function that has other preprocessor config conditionals.
      
      Let's see what odd architecture did something else strange in this area
      to break things.  But my arm64 cross build is clean.
      
      Fixes: 9caea000 ("parisc: Declare pci_iounmap() parisc version only when CONFIG_PCI enabled")
      Reported-by: default avatarNathan Chancellor <nathan@kernel.org>
      Cc: Helge Deller <deller@gmx.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Cc: Ulrich Teichert <krypton@ulrich-teichert.org>
      Cc: James Bottomley <James.Bottomley@hansenpartnership.com>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      316e8d79
  4. 19 Sep, 2021 18 commits
  5. 18 Sep, 2021 2 commits
    • Linus Torvalds's avatar
      alpha: move __udiv_qrnnd library function to arch/alpha/lib/ · d4d016ca
      Linus Torvalds authored
      We already had the implementation for __udiv_qrnnd (unsigned divide for
      multi-precision arithmetic) as part of the alpha math emulation code.
      
      But you can disable the math emulation code - even if you shouldn't -
      and then the MPI code that actually wants this functionality (and is
      needed by various crypto functions) will fail to build.
      
      So move the extended-precision divide code to be a regular library
      function, just like all the regular division code is.  That way ie is
      available regardless of math-emulation.
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      d4d016ca
    • Linus Torvalds's avatar
      alpha: mark 'Jensen' platform as no longer broken · ab41f75e
      Linus Torvalds authored
      Ok, it almost certainly is still broken on actual hardware, but the
      immediate reason for it having been marked BROKEN was a build error that
      is fixed by just making sure the low-level IO header file is included
      sufficiently early that the __EXTERN_INLINE hackery takes effect.
      
      This was marked broken back in 2017 by commit 1883c9f4 ("alpha: mark
      jensen as broken"), but Ulrich Teichert made me look at it as part of my
      cross-build work to make sure -Werror actually does the right thing.
      
      There are lots of alpha configurations that do not build cleanly, but
      now it's no longer because Jensen wouldn't be buildable.  That said,
      because the Jensen platform doesn't force PCI to be enabled (Jensen only
      had EISA), it ends up being somewhat interesting as a source of odd
      configs.
      Reported-by: default avatarUlrich Teichert <krypton@ulrich-teichert.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      ab41f75e