1. 28 Nov, 2018 7 commits
    • Lukas Wunner's avatar
      spi: bcm2835: Overcome sglist entry length limitation · 3bd7f658
      Lukas Wunner authored
      When in DMA mode, the BCM2835 SPI controller requires that the FIFO is
      accessed in 4 byte chunks.  This rule is not fulfilled if a transfer
      consists of multiple sglist entries, one per page, and the first entry
      starts in the middle of a page with an offset not a multiple of 4.
      
      The driver currently falls back to programmed I/O for such transfers,
      incurring a significant performance penalty.
      
      Overcome this hardware limitation by transferring the first few bytes of
      a transfer without DMA such that the remainder of the first sglist entry
      becomes a multiple of 4.  Specifics are provided in kerneldoc comments.
      
      An alternative approach would have been to split transfers in the
      ->prepare_message hook, but this may necessitate two transfers per page,
      defeating the goal of clustering multiple pages together in a single
      transfer for efficiency.  E.g. if the first TX sglist entry's length is
      23 and the first RX's is 40, the first transfer would send and receive
      23 bytes, the second 40 - 23 = 17 bytes, the third 4096 - 17 = 4079
      bytes, the fourth 4096 - 4079 = 17 bytes and so on.  In other words,
      O(n) transfers are necessary (n = number of sglist entries), whereas
      the algorithm implemented herein only requires O(1) additional work.
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Cc: Mathias Duckeck <m.duckeck@kunbus.de>
      Cc: Frank Pavlic <f.pavlic@kunbus.de>
      Cc: Martin Sperl <kernel@martin.sperl.org>
      Cc: Noralf Trønnes <noralf@tronnes.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      3bd7f658
    • Lukas Wunner's avatar
      spi: bcm2835: Document struct bcm2835_spi · acf0f856
      Lukas Wunner authored
      Document the driver's data structure to lower the barrier to entry for
      contributors.
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Cc: Mathias Duckeck <m.duckeck@kunbus.de>
      Cc: Frank Pavlic <f.pavlic@kunbus.de>
      Cc: Martin Sperl <kernel@martin.sperl.org>
      Cc: Noralf Trønnes <noralf@tronnes.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      acf0f856
    • Lukas Wunner's avatar
      spi: bcm2835: Drop unused code for native Chip Select · 5c09e42f
      Lukas Wunner authored
      Commit a30a555d ("spi: bcm2835: transform native-cs to gpio-cs on
      first spi_setup") disabled the use of hardware-controlled native Chip
      Select in favour of software-controlled GPIO Chip Select but left code
      to support the former untouched.  Remove it to simplify the driver and
      ease the addition of new features and further optimizations.
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Cc: Mathias Duckeck <m.duckeck@kunbus.de>
      Cc: Frank Pavlic <f.pavlic@kunbus.de>
      Cc: Martin Sperl <kernel@martin.sperl.org>
      Cc: Noralf Trønnes <noralf@tronnes.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      5c09e42f
    • Mark Brown's avatar
      c06eea7d
    • Lukas Wunner's avatar
      spi: bcm2835: Fix race on DMA termination · e82b0b38
      Lukas Wunner authored
      If a DMA transfer finishes orderly right when spi_transfer_one_message()
      determines that it has timed out, the callbacks bcm2835_spi_dma_done()
      and bcm2835_spi_handle_err() race to call dmaengine_terminate_all(),
      potentially leading to double termination.
      
      Prevent by atomically changing the dma_pending flag before calling
      dmaengine_terminate_all().
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Fixes: 3ecd37ed ("spi: bcm2835: enable dma modes for transfers meeting certain conditions")
      Cc: stable@vger.kernel.org # v4.2+
      Cc: Mathias Duckeck <m.duckeck@kunbus.de>
      Cc: Frank Pavlic <f.pavlic@kunbus.de>
      Cc: Martin Sperl <kernel@martin.sperl.org>
      Cc: Noralf Trønnes <noralf@tronnes.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      e82b0b38
    • Lukas Wunner's avatar
      spi: bcm2835: Fix book-keeping of DMA termination · dbc94411
      Lukas Wunner authored
      If submission of a DMA TX transfer succeeds but submission of the
      corresponding RX transfer does not, the BCM2835 SPI driver terminates
      the TX transfer but neglects to reset the dma_pending flag to false.
      
      Thus, if the next transfer uses interrupt mode (because it is shorter
      than BCM2835_SPI_DMA_MIN_LENGTH) and runs into a timeout,
      dmaengine_terminate_all() will be called both for TX (once more) and
      for RX (which was never started in the first place).  Fix it.
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Fixes: 3ecd37ed ("spi: bcm2835: enable dma modes for transfers meeting certain conditions")
      Cc: stable@vger.kernel.org # v4.2+
      Cc: Mathias Duckeck <m.duckeck@kunbus.de>
      Cc: Frank Pavlic <f.pavlic@kunbus.de>
      Cc: Martin Sperl <kernel@martin.sperl.org>
      Cc: Noralf Trønnes <noralf@tronnes.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      dbc94411
    • Lukas Wunner's avatar
      spi: bcm2835: Avoid finishing transfer prematurely in IRQ mode · 56c17234
      Lukas Wunner authored
      The IRQ handler bcm2835_spi_interrupt() first reads as much as possible
      from the RX FIFO, then writes as much as possible to the TX FIFO.
      Afterwards it decides whether the transfer is finished by checking if
      the TX FIFO is empty.
      
      If very few bytes were written to the TX FIFO, they may already have
      been transmitted by the time the FIFO's emptiness is checked.  As a
      result, the transfer will be declared finished and the chip will be
      reset without reading the corresponding received bytes from the RX FIFO.
      
      The odds of this happening increase with a high clock frequency (such
      that the TX FIFO drains quickly) and either passing "threadirqs" on the
      command line or enabling CONFIG_PREEMPT_RT_BASE (such that the IRQ
      handler may be preempted between filling the TX FIFO and checking its
      emptiness).
      
      Fix by instead checking whether rx_len has reached zero, which means
      that the transfer has been received in full.  This is also more
      efficient as it avoids one bus read access per interrupt.  Note that
      bcm2835_spi_transfer_one_poll() likewise uses rx_len to determine
      whether the transfer has finished.
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Fixes: e34ff011 ("spi: bcm2835: move to the transfer_one driver model")
      Cc: stable@vger.kernel.org # v4.1+
      Cc: Mathias Duckeck <m.duckeck@kunbus.de>
      Cc: Frank Pavlic <f.pavlic@kunbus.de>
      Cc: Martin Sperl <kernel@martin.sperl.org>
      Cc: Noralf Trønnes <noralf@tronnes.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      56c17234
  2. 27 Nov, 2018 4 commits
  3. 23 Nov, 2018 1 commit
  4. 17 Nov, 2018 1 commit
  5. 16 Nov, 2018 2 commits
  6. 15 Nov, 2018 1 commit
  7. 14 Nov, 2018 2 commits
  8. 13 Nov, 2018 9 commits
  9. 07 Nov, 2018 3 commits
  10. 06 Nov, 2018 1 commit
  11. 05 Nov, 2018 9 commits