1. 03 3月, 2021 1 次提交
    • G
      MMC: added alternative MMC driver · d4e40dd0
      gellert 提交于
      raspberrypi inclusion
      category: feature
      bugzilla: 50432
      
      --------------------------------
      
      mmc: Disable CMD23 transfers on all cards
      
      Pending wire-level investigation of these types of transfers
      and associated errors on bcm2835-mmc, disable for now. Fallback of
      CMD18/CMD25 transfers will be used automatically by the MMC layer.
      
      Reported/Tested-by: Gellert Weisz <gellert@raspberrypi.org>
      
      mmc: bcm2835-mmc: enable DT support for all architectures
      
      Both ARCH_BCM2835 and ARCH_BCM270x are built with OF now.
      Enable Device Tree support for all architectures.
      Signed-off-by: NNoralf Trønnes <noralf@tronnes.org>
      
      mmc: bcm2835-mmc: fix probe error handling
      
      Probe error handling is broken in several places.
      Simplify error handling by using device managed functions.
      Replace pr_{err,info} with dev_{err,info}.
      Signed-off-by: NNoralf Trønnes <noralf@tronnes.org>
      
      bcm2835-mmc: Add locks when accessing sdhost registers
      
      bcm2835-mmc: Add range of debug options for slowing things down
      
      bcm2835-mmc: Add option to disable some delays
      
      bcm2835-mmc: Add option to disable MMC_QUIRK_BLK_NO_CMD23
      
      bcm2835-mmc: Default to disabling MMC_QUIRK_BLK_NO_CMD23
      
      bcm2835-mmc: Adding overclocking option
      
      Allow a different clock speed to be substitued for a requested 50MHz.
      This option is exposed using the "overclock_50" DT parameter.
      Note that the mmc interface is restricted to EVEN integer divisions of
      250MHz, and the highest sensible option is 63 (250/4 = 62.5), the
      next being 125 (250/2) which is much too high.
      
      Use at your own risk.
      
      bcm2835-mmc: Round up the overclock, so 62 works for 62.5Mhz
      
      Also only warn once for each overclock setting.
      
      mmc: bcm2835-mmc: Make available on ARCH_BCM2835
      
      Make the bcm2835-mmc driver available for use on ARCH_BCM2835.
      Signed-off-by: NNoralf Trønnes <noralf@tronnes.org>
      
      BCM270x_DT: add bcm2835-mmc entry
      
      Add Device Tree entry for bcm2835-mmc.
      In non-DT mode, don't add the device in the board file.
      Signed-off-by: NNoralf Trønnes <noralf@tronnes.org>
      
      bcm2835-mmc: Don't overwrite MMC capabilities from DT
      
      bcm2835-mmc: Don't override bus width capabilities from devicetree
      
      Take out the force setting of the MMC_CAP_4_BIT_DATA host capability
      so that the result read from devicetree via mmc_of_parse() is
      preserved.
      
      bcm2835-mmc: Only claim one DMA channel
      
      With both MMC controllers enabled there are few DMA channels left. The
      bcm2835-mmc driver only uses DMA in one direction at a time, so it
      doesn't need to claim two channels.
      
      See: https://github.com/raspberrypi/linux/issues/1327Signed-off-by: NPhil Elwell <phil@raspberrypi.org>
      
      bcm2835-mmc: New timer API
      
      mmc: bcm2835-mmc: Support underclocking
      
      Support underclocking of the SD bus using the max-frequency DT property
      (which currently has no DT parameter). The sd_overclock parameter
      already provides another way to achieve the same thing which should be
      equivalent in end result, but it is a bug not to support max-frequency
      as well.
      
      See: https://github.com/raspberrypi/linux/issues/2350Signed-off-by: NPhil Elwell <phil@raspberrypi.org>
      
      mmc/bcm2835: Recover from MMC_SEND_EXT_CSD
      
      If the user issues an "mmc extcsd read", the SD controller receives
      what it thinks is a SEND_IF_COND command with an unexpected data block.
      The resulting operations leave the FSM stuck in READWAIT, a state which
      persists until the MMC framework resets the controller, by which point
      the root filesystem is likely to have been unmounted.
      
      A less heavyweight solution is to detect the condition and nudge the
      FSM by asserting the (self-clearing) FORCE_DATA_MODE bit.
      
      N.B. This workaround was essentially discovered by accident and without
      a full understanding the inner workings of the controller, so it is
      fortunate that the "fix" only modifies error paths.
      
      See: https://github.com/raspberrypi/linux/issues/2728Signed-off-by: NPhil Elwell <phil@raspberrypi.org>
      
      bcm2835-mmc: Fix DMA channel leak
      
      The BCM2835 MMC host driver requests a DMA channel on probe but neglects
      to release the channel in the probe error path and on driver unbind.
      
      I'm seeing this happen on every boot of the Compute Module 3: On first
      driver probe, DMA channel 2 is allocated and then leaked with a "could
      not get clk, deferring probe" message. On second driver probe, channel 4
      is allocated.
      
      Fix it.
      Signed-off-by: NLukas Wunner <lukas@wunner.de>
      Cc: Frank Pavlic <f.pavlic@kunbus.de>
      
      bcm2835-mmc: Fix struct mmc_host leak on probe
      
      The BCM2835 MMC host driver requests the bus address of the host's
      register map on probe.  If that fails, the driver leaks the struct
      mmc_host allocated earlier.
      
      Fix it.
      Signed-off-by: NLukas Wunner <lukas@wunner.de>
      Cc: Frank Pavlic <f.pavlic@kunbus.de>
      
      bcm2835-mmc: Fix duplicate free_irq() on remove
      
      The BCM2835 MMC host driver requests its interrupt as a device-managed
      resource, so the interrupt is automatically freed after the driver is
      unbound.
      
      However on driver unbind, bcm2835_mmc_remove() frees the interrupt
      explicitly to avoid invocation of the interrupt handler after driver
      structures have been torn down.
      
      The interrupt is thus freed twice, leading to a WARN splat in
      __free_irq().  Fix by not requesting the interrupt as a device-managed
      resource.
      Signed-off-by: NLukas Wunner <lukas@wunner.de>
      Cc: Frank Pavlic <f.pavlic@kunbus.de>
      
      bcm2835-mmc: Handle mmc_add_host() errors
      
      The BCM2835 MMC host driver calls mmc_add_host() but doesn't check its
      return value.  Errors occurring in that function are therefore not
      handled.  Fix it.
      Signed-off-by: NLukas Wunner <lukas@wunner.de>
      Cc: Frank Pavlic <f.pavlic@kunbus.de>
      
      bcm2835-mmc: Deduplicate reset of driver data on remove
      
      The BCM2835 MMC host driver sets the device's driver data pointer to
      NULL on ->remove() even though the driver core subsequently does the
      same in __device_release_driver().  Drop the duplicate assignment.
      Signed-off-by: NLukas Wunner <lukas@wunner.de>
      Cc: Frank Pavlic <f.pavlic@kunbus.de>
      
      bcm2835_mmc: Remove vestigial threaded IRQ
      
      With SDIO processing now managed by the MMC framework with a
      workqueue, the bcm2835_mmc driver no longer needs a threaded
      IRQ.
      Signed-off-by: NPhil Elwell <phil@raspberrypi.org>
      
      Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers.
      This prevents DMA leaks.
      Signed-off-by: NYaroslav Rosomakho <yaroslavros@gmail.com>
      
      Limit max_req_size under arm64 (or any other platform that uses swiotlb) to prevent potential buffer overflow due to bouncing.
      Signed-off-by: NYaroslav Rosomakho <yaroslavros@gmail.com>
      Signed-off-by: NFang Yafen <yafen@iscas.ac.cn>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      d4e40dd0
  2. 25 9月, 2020 1 次提交
  3. 13 7月, 2020 2 次提交
  4. 28 5月, 2020 1 次提交
  5. 26 3月, 2020 1 次提交
    • U
      mmc: core: Re-work the code for eMMC sanitize · 55c2b8b9
      Ulf Hansson 提交于
      The error path for sanitize operations that completes with -ETIMEDOUT, is
      tightly coupled with the internal request handling code of the core. More
      precisely, mmc_wait_for_req_done() checks for specific sanitize errors.
      This is not only inefficient as it affects all types of requests, but also
      hackish.
      
      Therefore, let's improve the behaviour by moving the error path out of the
      mmc core. To do that, retuning needs to be held while running the sanitize
      operation.
      
      Moreover, to avoid exporting unnecessary symbols to the mmc block module,
      let's move the code into the mmc_ops.c file. While updating the actual
      code, let's also take the opportunity to clean up some of the mess around
      it.
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      Link: https://lore.kernel.org/r/20200316152152.15122-1-ulf.hansson@linaro.org
      55c2b8b9
  6. 24 3月, 2020 1 次提交
  7. 11 3月, 2020 1 次提交
  8. 20 1月, 2020 1 次提交
  9. 14 11月, 2019 2 次提交
    • U
      mmc: core: Re-work HW reset for SDIO cards · 2ac55d5e
      Ulf Hansson 提交于
      It have turned out that it's not a good idea to unconditionally do a power
      cycle and then to re-initialize the SDIO card, as currently done through
      mmc_hw_reset() -> mmc_sdio_hw_reset(). This because there may be multiple
      SDIO func drivers probed, who also shares the same SDIO card.
      
      To address these scenarios, one may be tempted to use a notification
      mechanism, as to allow the core to inform each of the probed func drivers,
      about an ongoing HW reset. However, supporting such an operation from the
      func driver point of view, may not be entirely trivial.
      
      Therefore, let's use a more simplistic approach to solve the problem, by
      instead forcing the card to be removed and re-detected, via scheduling a
      rescan-work. In this way, we can rely on existing infrastructure, as the
      func driver's ->remove() and ->probe() callbacks, becomes invoked to deal
      with the cleanup and the re-initialization.
      
      This solution may be considered as rather heavy, especially if a func
      driver doesn't share its card with other func drivers. To address this,
      let's keep the current immediate HW reset option as well, but run it only
      when there is one func driver probed for the card.
      
      Finally, to allow the caller of mmc_hw_reset(), to understand if the reset
      is being asynchronously managed from a scheduled work, it returns 1
      (propagated from mmc_sdio_hw_reset()). If the HW reset is executed
      successfully and synchronously it returns 0, which maintains the existing
      behaviour.
      Reviewed-by: NDouglas Anderson <dianders@chromium.org>
      Tested-by: NDouglas Anderson <dianders@chromium.org>
      Cc: stable@vger.kernel.org # v5.4+
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      2ac55d5e
    • U
      mmc: core: Drop check for mmc_card_is_removable() in mmc_rescan() · 99b4ddd8
      Ulf Hansson 提交于
      Upfront in mmc_rescan() we use the host->rescan_entered flag, to allow
      scanning only once for non-removable cards. Therefore, it's also not
      possible that we can have a corresponding card bus attached (host->bus_ops
      is NULL), when we are scanning non-removable cards.
      
      For this reason, let' drop the check for mmc_card_is_removable() as it's
      redundant.
      Reviewed-by: NDouglas Anderson <dianders@chromium.org>
      Tested-by: NDouglas Anderson <dianders@chromium.org>
      Cc: stable@vger.kernel.org # v5.4+
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      99b4ddd8
  10. 19 6月, 2019 1 次提交
  11. 18 6月, 2019 1 次提交
    • D
      mmc: core: API to temporarily disable retuning for SDIO CRC errors · 0a55f4ab
      Douglas Anderson 提交于
      Normally when the MMC core sees an "-EILSEQ" error returned by a host
      controller then it will trigger a retuning of the card.  This is
      generally a good idea.
      
      However, if a command is expected to sometimes cause transfer errors
      then these transfer errors shouldn't cause a re-tuning.  This
      re-tuning will be a needless waste of time.  One example case where a
      transfer is expected to cause errors is when transitioning between
      idle (sometimes referred to as "sleep" in Broadcom code) and active
      state on certain Broadcom WiFi SDIO cards.  Specifically if the card
      was already transitioning between states when the command was sent it
      could cause an error on the SDIO bus.
      
      Let's add an API that the SDIO function drivers can call that will
      temporarily disable the auto-tuning functionality.  Then we can add a
      call to this in the Broadcom WiFi driver and any other driver that
      might have similar needs.
      
      NOTE: this makes the assumption that the card is already tuned well
      enough that it's OK to disable the auto-retuning during one of these
      error-prone situations.  Presumably the driver code performing the
      error-prone transfer knows how to recover / retry from errors.  ...and
      after we can get back to a state where transfers are no longer
      error-prone then we can enable the auto-retuning again.  If we truly
      find ourselves in a case where the card needs to be retuned sometimes
      to handle one of these error-prone transfers then we can always try a
      few transfers first without auto-retuning and then re-try with
      auto-retuning if the first few fail.
      
      Without this change on rk3288-veyron-minnie I periodically see this in
      the logs of a machine just sitting there idle:
        dwmmc_rockchip ff0d0000.dwmmc: Successfully tuned phase to XYZ
      
      Cc: stable@vger.kernel.org #v4.18+
      Signed-off-by: NDouglas Anderson <dianders@chromium.org>
      Acked-by: NAdrian Hunter <adrian.hunter@intel.com>
      Acked-by: NKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      0a55f4ab
  12. 01 3月, 2019 1 次提交
    • J
      mmc:fix a bug when max_discard is 0 · d4721339
      Jiong Wu 提交于
      The original purpose of the code I fix is to replace max_discard with
      max_trim if max_trim is less than max_discard. When max_discard is 0
      we should replace max_discard with max_trim as well, because
      max_discard equals 0 happens only when the max_do_calc_max_discard
      process is overflowed, so if mmc_can_trim(card) is true, max_discard
      should be replaced by an available max_trim.
      However, in the original code, there are two lines of code interfere
      the right process.
      1) if (max_discard && mmc_can_trim(card))
      when max_discard is 0, it skips the process checking if max_discard
      needs to be replaced with max_trim.
      2) if (max_trim < max_discard)
      the condition is false when max_discard is 0. it also skips the process
      that replaces max_discard with max_trim, in fact, we should replace the
      0-valued max_discard with max_trim.
      Signed-off-by: NJiong Wu <Lohengrin1024@gmail.com>
      Fixes: b305882f (mmc: core: optimize mmc_calc_max_discard)
      Cc: stable@vger.kernel.org # v4.17+
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      d4721339
  13. 28 2月, 2019 2 次提交
    • A
      mmc: core: Add sd discard timeout · ad9be7ff
      Avri Altman 提交于
      The busy timeout is 250msec per discard command.
      Signed-off-by: NAvri Altman <avri.altman@wdc.com>
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      ad9be7ff
    • A
      mmc: core: Add discard support to sd · bc47e2f6
      Avri Altman 提交于
      SD spec v5.1 adds discard support. The flows and commands are similar to
      mmc, so just set the discard arg in CMD38.
      
      A host which supports DISCARD shall check if the DISCARD_SUPPORT (b313)
      is set in the SD_STATUS register.  If the card does not support discard,
      the host shall not issue DISCARD command, but ERASE command instead.
      
      Post the DISCARD operation, the card may de-allocate the discarded
      blocks partially or completely. So the host mustn't make any assumptions
      concerning the content of the discarded region. This is unlike ERASE
      command, in which the region is guaranteed to contain either '0's or
      '1's, depends on the content of DATA_STAT_AFTER_ERASE (b55) in the scr
      register.
      
      One more important difference compared to ERASE is the busy timeout
      which we will address on the next patch.
      Signed-off-by: NAvri Altman <avri.altman@wdc.com>
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      bc47e2f6
  14. 27 2月, 2019 1 次提交
  15. 26 2月, 2019 1 次提交
  16. 25 2月, 2019 3 次提交
  17. 17 12月, 2018 2 次提交
  18. 16 7月, 2018 2 次提交
    • U
      mmc: core: Drop the unused mmc_power_save|restore_host() · 29772f8a
      Ulf Hansson 提交于
      The last user of mmc_power_save|restore_host() APIs is gone, hence let's
      drop them. Drop also the corresponding bus_ops callback,
      ->power_save|restore() as those becomes redundant.
      
      Cc: Tony Lindgren <tony@atomide.com>
      Cc: Eyal Reizer <eyalreizer@gmail.com>
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      29772f8a
    • S
      mmc: core: Adjust and reuse the macro of R1_STATUS(x) · a94a7483
      Shawn Lin 提交于
      R1_STATUS(x) now is only used by ioctl_rpmb_card_status_poll(),
      which checks all bits as possible. But according to the spec,
      bit 17 and bit 18 should be ignored, as well bit 14 which is
      reserved(must be set to 0) quoting from the spec and these rule
      apply to all places checking the device status. So change
      its checking from 0xFFFFE000 to 0xFFF9A000.
      
      As a bonus, we reuse it for mmc_do_erase() as well as
      mmc_switch_status_error().
      (1) Currently mmc_switch_status_error() doesn't check bit 25, but
      it means device is locked but not unlocked by CMD42 prior to any
      operations which need check busy, which is also not allowed.
      (2) mmc_do_erase() also forgot to to check bit 15, WP_ERASE_SKIP.
      The spec says "Only partial address space was erased due to existing
      write protected blocks.", which obviously means we should fail this I/O.
      Otherwise, the partial erased data stored in nonvalatile flash violates
      the data integrity from the view of I/O owner, which probably confuse
      it when further used.
      
      So reusing R1_STATUS for them not only improve the readability but also
      slove real problems.
      Signed-off-by: NShawn Lin <shawn.lin@rock-chips.com>
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      a94a7483
  19. 29 5月, 2018 1 次提交
    • M
      mmc: Throttle calls to MMC_SEND_STATUS during mmc_do_erase() · 833b5117
      Martin Hicks 提交于
      This drastically reduces the rate at which the MMC_SEND_STATUS cmd polls
      for completion of the MMC Erase operation.  The patch does this by adding
      a backoff sleep that starts by sleeping for short intervals (128-256us),
      and ramps up to sleeping for 32-64ms.
      
      Even on very quickly completing erase operations, the loop iterates a few
      times, so not too much extra latency is added to these commands.
      
      For long running discard operarations, like a full-device secure discard,
      this change drops the interrupt rates on my single-core NXP I.MX6UL from
      45000/s to about 20/s, and greatly improves system responsiveness.
      Signed-off-by: NMartin Hicks <mort@bork.org>
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      833b5117
  20. 21 5月, 2018 1 次提交
    • S
      mmc: core: add tunable delay waiting for power to be stable · 6d796c68
      Shawn Lin 提交于
      The hard-coded 10ms delay in mmc_power_up came from
      commit 79bccc5a ("mmc: increase power up delay"), which said "The TI
      controller on Toshiba Tecra M5 needs more time to power up or the cards
      will init incorrectly or not at all." But it's too engineering solution
      for a special board but force all platforms to wait for that long time,
      especially painful for mmc_power_up for eMMC when booting.
      
      However, it's added since 2009, and we can't tell if other platforms
      benefit from it. But in practise, the modern hardware are most likely to
      have a stable power supply with 1ms after setting it for no matter PMIC
      or discrete power. And more importnatly, most regulators implement the
      callback of ->set_voltage_time_sel() for regulator core to wait for
      specific period of time for the power supply to be stable, which means
      once regulator_set_voltage_* return, the power should reach the the
      minimum voltage that works for initialization. Of course, if there
      are some other ways for host to power the card, we should allow them
      to argue a suitable delay as well.
      
      With this patch, we could assign the delay from firmware, or we could
      assigne it via ->set_ios() callback from host drivers.
      Signed-off-by: NShawn Lin <shawn.lin@rock-chips.com>
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      6d796c68
  21. 08 5月, 2018 4 次提交
  22. 05 3月, 2018 2 次提交
  23. 18 12月, 2017 1 次提交
    • D
      mmc: avoid removing non-removable hosts during suspend · de8dcc3d
      Daniel Drake 提交于
      The Weibu F3C MiniPC has an onboard AP6255 module, presenting
      two SDIO functions on a single MMC host (Bluetooth/btsdio and
      WiFi/brcmfmac), and the mmc layer correctly detects this as
      non-removable.
      
      After suspend/resume, the wifi and bluetooth interfaces disappear
      and do not get probed again.
      
      The conditions here are:
      
       1. During suspend, we reach mmc_pm_notify()
      
       2. mmc_pm_notify() calls mmc_sdio_pre_suspend() to see if we can
          suspend the SDIO host. However, mmc_sdio_pre_suspend() returns
          -ENOSYS because btsdio_driver does not have a suspend method.
      
       3. mmc_pm_notify() proceeds to remove the card
      
       4. Upon resume, mmc_rescan() does nothing with this host, because of
          the rescan_entered check which aims to only scan a non-removable
          device a single time (i.e. during boot).
      
      Fix the loss of functionality by detecting that we are unable to
      suspend a non-removable host, so avoid the forced removal in that
      case. The comment above this function already indicates that this
      code was only intended for removable devices.
      Signed-off-by: NDaniel Drake <drake@endlessm.com>
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      de8dcc3d
  24. 11 12月, 2017 5 次提交
  25. 30 10月, 2017 1 次提交