-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bcm2835-sdhost and bcm2835-mmc ignore the max-frequency DT property #2350
Labels
Comments
pelwell
pushed a commit
that referenced
this issue
Jan 22, 2018
Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
pelwell
pushed a commit
that referenced
this issue
Jan 22, 2018
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: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
pelwell
pushed a commit
that referenced
this issue
Jan 22, 2018
Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
pelwell
pushed a commit
that referenced
this issue
Jan 22, 2018
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: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
pelwell
pushed a commit
that referenced
this issue
Jan 22, 2018
Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
pelwell
pushed a commit
that referenced
this issue
Jan 22, 2018
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: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Jan 22, 2018
Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Jan 22, 2018
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: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Jan 25, 2018
Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Jan 25, 2018
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: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Jan 29, 2018
Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Jan 29, 2018
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: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Jan 31, 2018
Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Jan 31, 2018
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: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
TiejunChina
pushed a commit
to TiejunChina/linux
that referenced
this issue
Feb 2, 2018
Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: raspberrypi#2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
TiejunChina
pushed a commit
to TiejunChina/linux
that referenced
this issue
Feb 2, 2018
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: raspberrypi#2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Feb 5, 2018
Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Feb 5, 2018
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: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Feb 5, 2018
Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Feb 5, 2018
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: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Feb 5, 2018
Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Feb 5, 2018
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: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Feb 9, 2018
Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Feb 9, 2018
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: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Feb 12, 2018
Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Feb 12, 2018
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: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Feb 13, 2018
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Feb 13, 2018
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
TiejunChina
pushed a commit
to TiejunChina/linux
that referenced
this issue
Feb 14, 2018
Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: raspberrypi#2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
popcornmix
pushed a commit
that referenced
this issue
Dec 16, 2024
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Dec 16, 2024
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835-sdhost: 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: #2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Fix warnings on arm64 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Allow for sg entries that cross pages The dma_complete handling code calculates a virtual address for a page then adds an offset, but if the offset is more than a page and HIGHMEM is in use then the summed address could be in an unmapped (or just incorrect) page. The upstream SDHOST driver allows for this possibility - copy the code that does so. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Fix DMA channel leak on error/remove Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Support 64-bit physical addresses Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Replace obsolete struct timeval struct timeval has been retired due to the impending linux 32-bit tv_sec rollover (only 18 years to go) - timespec64 is the obvious replacement. Signed-off-by: Phil Elwell <phil@raspberrypi.com> mmc: sdhost: Pass DT pointer to rpi_firmware_get Using the rpi_firmware API as intended allows proper reference counting of the firmware device and means we can remove a downstream patch to the firmware driver. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use DT to configure logging Retrieve the system timer base address directly from DT. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Fail gracefully with bad dtb The logging timestamps depend on the existence of a bcm2835-system-timer node. If this node doesn't exist, leave the logging disabled rather than crashing. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Dec 20, 2024
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Dec 20, 2024
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835-sdhost: 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: #2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Fix warnings on arm64 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Allow for sg entries that cross pages The dma_complete handling code calculates a virtual address for a page then adds an offset, but if the offset is more than a page and HIGHMEM is in use then the summed address could be in an unmapped (or just incorrect) page. The upstream SDHOST driver allows for this possibility - copy the code that does so. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Fix DMA channel leak on error/remove Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Support 64-bit physical addresses Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Replace obsolete struct timeval struct timeval has been retired due to the impending linux 32-bit tv_sec rollover (only 18 years to go) - timespec64 is the obvious replacement. Signed-off-by: Phil Elwell <phil@raspberrypi.com> mmc: sdhost: Pass DT pointer to rpi_firmware_get Using the rpi_firmware API as intended allows proper reference counting of the firmware device and means we can remove a downstream patch to the firmware driver. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use DT to configure logging Retrieve the system timer base address directly from DT. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Fail gracefully with bad dtb The logging timestamps depend on the existence of a bcm2835-system-timer node. If this node doesn't exist, leave the logging disabled rather than crashing. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 2, 2025
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 2, 2025
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835-sdhost: 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: #2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Fix warnings on arm64 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Allow for sg entries that cross pages The dma_complete handling code calculates a virtual address for a page then adds an offset, but if the offset is more than a page and HIGHMEM is in use then the summed address could be in an unmapped (or just incorrect) page. The upstream SDHOST driver allows for this possibility - copy the code that does so. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Fix DMA channel leak on error/remove Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Support 64-bit physical addresses Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Replace obsolete struct timeval struct timeval has been retired due to the impending linux 32-bit tv_sec rollover (only 18 years to go) - timespec64 is the obvious replacement. Signed-off-by: Phil Elwell <phil@raspberrypi.com> mmc: sdhost: Pass DT pointer to rpi_firmware_get Using the rpi_firmware API as intended allows proper reference counting of the firmware device and means we can remove a downstream patch to the firmware driver. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use DT to configure logging Retrieve the system timer base address directly from DT. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Fail gracefully with bad dtb The logging timestamps depend on the existence of a bcm2835-system-timer node. If this node doesn't exist, leave the logging disabled rather than crashing. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 2, 2025
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 2, 2025
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835-sdhost: 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: #2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Fix warnings on arm64 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Allow for sg entries that cross pages The dma_complete handling code calculates a virtual address for a page then adds an offset, but if the offset is more than a page and HIGHMEM is in use then the summed address could be in an unmapped (or just incorrect) page. The upstream SDHOST driver allows for this possibility - copy the code that does so. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Fix DMA channel leak on error/remove Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Support 64-bit physical addresses Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Replace obsolete struct timeval struct timeval has been retired due to the impending linux 32-bit tv_sec rollover (only 18 years to go) - timespec64 is the obvious replacement. Signed-off-by: Phil Elwell <phil@raspberrypi.com> mmc: sdhost: Pass DT pointer to rpi_firmware_get Using the rpi_firmware API as intended allows proper reference counting of the firmware device and means we can remove a downstream patch to the firmware driver. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use DT to configure logging Retrieve the system timer base address directly from DT. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Fail gracefully with bad dtb The logging timestamps depend on the existence of a bcm2835-system-timer node. If this node doesn't exist, leave the logging disabled rather than crashing. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 6, 2025
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 6, 2025
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835-sdhost: 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: #2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Fix warnings on arm64 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Allow for sg entries that cross pages The dma_complete handling code calculates a virtual address for a page then adds an offset, but if the offset is more than a page and HIGHMEM is in use then the summed address could be in an unmapped (or just incorrect) page. The upstream SDHOST driver allows for this possibility - copy the code that does so. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Fix DMA channel leak on error/remove Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Support 64-bit physical addresses Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Replace obsolete struct timeval struct timeval has been retired due to the impending linux 32-bit tv_sec rollover (only 18 years to go) - timespec64 is the obvious replacement. Signed-off-by: Phil Elwell <phil@raspberrypi.com> mmc: sdhost: Pass DT pointer to rpi_firmware_get Using the rpi_firmware API as intended allows proper reference counting of the firmware device and means we can remove a downstream patch to the firmware driver. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use DT to configure logging Retrieve the system timer base address directly from DT. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Fail gracefully with bad dtb The logging timestamps depend on the existence of a bcm2835-system-timer node. If this node doesn't exist, leave the logging disabled rather than crashing. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 10, 2025
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 10, 2025
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835-sdhost: 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: #2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Fix warnings on arm64 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Allow for sg entries that cross pages The dma_complete handling code calculates a virtual address for a page then adds an offset, but if the offset is more than a page and HIGHMEM is in use then the summed address could be in an unmapped (or just incorrect) page. The upstream SDHOST driver allows for this possibility - copy the code that does so. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Fix DMA channel leak on error/remove Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Support 64-bit physical addresses Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Replace obsolete struct timeval struct timeval has been retired due to the impending linux 32-bit tv_sec rollover (only 18 years to go) - timespec64 is the obvious replacement. Signed-off-by: Phil Elwell <phil@raspberrypi.com> mmc: sdhost: Pass DT pointer to rpi_firmware_get Using the rpi_firmware API as intended allows proper reference counting of the firmware device and means we can remove a downstream patch to the firmware driver. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use DT to configure logging Retrieve the system timer base address directly from DT. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Fail gracefully with bad dtb The logging timestamps depend on the existence of a bcm2835-system-timer node. If this node doesn't exist, leave the logging disabled rather than crashing. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 13, 2025
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 13, 2025
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835-sdhost: 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: #2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Fix warnings on arm64 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Allow for sg entries that cross pages The dma_complete handling code calculates a virtual address for a page then adds an offset, but if the offset is more than a page and HIGHMEM is in use then the summed address could be in an unmapped (or just incorrect) page. The upstream SDHOST driver allows for this possibility - copy the code that does so. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Fix DMA channel leak on error/remove Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Support 64-bit physical addresses Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Replace obsolete struct timeval struct timeval has been retired due to the impending linux 32-bit tv_sec rollover (only 18 years to go) - timespec64 is the obvious replacement. Signed-off-by: Phil Elwell <phil@raspberrypi.com> mmc: sdhost: Pass DT pointer to rpi_firmware_get Using the rpi_firmware API as intended allows proper reference counting of the firmware device and means we can remove a downstream patch to the firmware driver. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use DT to configure logging Retrieve the system timer base address directly from DT. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Fail gracefully with bad dtb The logging timestamps depend on the existence of a bcm2835-system-timer node. If this node doesn't exist, leave the logging disabled rather than crashing. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 17, 2025
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 17, 2025
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835-sdhost: 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: #2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Fix warnings on arm64 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Allow for sg entries that cross pages The dma_complete handling code calculates a virtual address for a page then adds an offset, but if the offset is more than a page and HIGHMEM is in use then the summed address could be in an unmapped (or just incorrect) page. The upstream SDHOST driver allows for this possibility - copy the code that does so. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Fix DMA channel leak on error/remove Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Support 64-bit physical addresses Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Replace obsolete struct timeval struct timeval has been retired due to the impending linux 32-bit tv_sec rollover (only 18 years to go) - timespec64 is the obvious replacement. Signed-off-by: Phil Elwell <phil@raspberrypi.com> mmc: sdhost: Pass DT pointer to rpi_firmware_get Using the rpi_firmware API as intended allows proper reference counting of the firmware device and means we can remove a downstream patch to the firmware driver. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use DT to configure logging Retrieve the system timer base address directly from DT. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Fail gracefully with bad dtb The logging timestamps depend on the existence of a bcm2835-system-timer node. If this node doesn't exist, leave the logging disabled rather than crashing. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 20, 2025
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 20, 2025
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835-sdhost: 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: #2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Fix warnings on arm64 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Allow for sg entries that cross pages The dma_complete handling code calculates a virtual address for a page then adds an offset, but if the offset is more than a page and HIGHMEM is in use then the summed address could be in an unmapped (or just incorrect) page. The upstream SDHOST driver allows for this possibility - copy the code that does so. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Fix DMA channel leak on error/remove Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Support 64-bit physical addresses Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Replace obsolete struct timeval struct timeval has been retired due to the impending linux 32-bit tv_sec rollover (only 18 years to go) - timespec64 is the obvious replacement. Signed-off-by: Phil Elwell <phil@raspberrypi.com> mmc: sdhost: Pass DT pointer to rpi_firmware_get Using the rpi_firmware API as intended allows proper reference counting of the firmware device and means we can remove a downstream patch to the firmware driver. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use DT to configure logging Retrieve the system timer base address directly from DT. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Fail gracefully with bad dtb The logging timestamps depend on the existence of a bcm2835-system-timer node. If this node doesn't exist, leave the logging disabled rather than crashing. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 24, 2025
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Jan 24, 2025
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835-sdhost: 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: #2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Fix warnings on arm64 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Allow for sg entries that cross pages The dma_complete handling code calculates a virtual address for a page then adds an offset, but if the offset is more than a page and HIGHMEM is in use then the summed address could be in an unmapped (or just incorrect) page. The upstream SDHOST driver allows for this possibility - copy the code that does so. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Fix DMA channel leak on error/remove Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Support 64-bit physical addresses Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Replace obsolete struct timeval struct timeval has been retired due to the impending linux 32-bit tv_sec rollover (only 18 years to go) - timespec64 is the obvious replacement. Signed-off-by: Phil Elwell <phil@raspberrypi.com> mmc: sdhost: Pass DT pointer to rpi_firmware_get Using the rpi_firmware API as intended allows proper reference counting of the firmware device and means we can remove a downstream patch to the firmware driver. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use DT to configure logging Retrieve the system timer base address directly from DT. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Fail gracefully with bad dtb The logging timestamps depend on the existence of a bcm2835-system-timer node. If this node doesn't exist, leave the logging disabled rather than crashing. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Feb 3, 2025
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Feb 3, 2025
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835-sdhost: 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: #2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Fix warnings on arm64 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Allow for sg entries that cross pages The dma_complete handling code calculates a virtual address for a page then adds an offset, but if the offset is more than a page and HIGHMEM is in use then the summed address could be in an unmapped (or just incorrect) page. The upstream SDHOST driver allows for this possibility - copy the code that does so. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Fix DMA channel leak on error/remove Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Support 64-bit physical addresses Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Replace obsolete struct timeval struct timeval has been retired due to the impending linux 32-bit tv_sec rollover (only 18 years to go) - timespec64 is the obvious replacement. Signed-off-by: Phil Elwell <phil@raspberrypi.com> mmc: sdhost: Pass DT pointer to rpi_firmware_get Using the rpi_firmware API as intended allows proper reference counting of the firmware device and means we can remove a downstream patch to the firmware driver. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use DT to configure logging Retrieve the system timer base address directly from DT. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Fail gracefully with bad dtb The logging timestamps depend on the existence of a bcm2835-system-timer node. If this node doesn't exist, leave the logging disabled rather than crashing. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Feb 3, 2025
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Feb 3, 2025
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835-sdhost: 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: #2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Fix warnings on arm64 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Allow for sg entries that cross pages The dma_complete handling code calculates a virtual address for a page then adds an offset, but if the offset is more than a page and HIGHMEM is in use then the summed address could be in an unmapped (or just incorrect) page. The upstream SDHOST driver allows for this possibility - copy the code that does so. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Fix DMA channel leak on error/remove Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Support 64-bit physical addresses Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Replace obsolete struct timeval struct timeval has been retired due to the impending linux 32-bit tv_sec rollover (only 18 years to go) - timespec64 is the obvious replacement. Signed-off-by: Phil Elwell <phil@raspberrypi.com> mmc: sdhost: Pass DT pointer to rpi_firmware_get Using the rpi_firmware API as intended allows proper reference counting of the firmware device and means we can remove a downstream patch to the firmware driver. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use DT to configure logging Retrieve the system timer base address directly from DT. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Fail gracefully with bad dtb The logging timestamps depend on the existence of a bcm2835-system-timer node. If this node doesn't exist, leave the logging disabled rather than crashing. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
6by9
pushed a commit
to 6by9/linux
that referenced
this issue
Feb 6, 2025
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: raspberrypi#1327 Signed-off-by: Phil 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: raspberrypi#2350 Signed-off-by: Phil 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: raspberrypi#2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Feb 10, 2025
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Feb 10, 2025
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Feb 10, 2025
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835-sdhost: 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: #2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Fix warnings on arm64 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Allow for sg entries that cross pages The dma_complete handling code calculates a virtual address for a page then adds an offset, but if the offset is more than a page and HIGHMEM is in use then the summed address could be in an unmapped (or just incorrect) page. The upstream SDHOST driver allows for this possibility - copy the code that does so. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Fix DMA channel leak on error/remove Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Support 64-bit physical addresses Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Replace obsolete struct timeval struct timeval has been retired due to the impending linux 32-bit tv_sec rollover (only 18 years to go) - timespec64 is the obvious replacement. Signed-off-by: Phil Elwell <phil@raspberrypi.com> mmc: sdhost: Pass DT pointer to rpi_firmware_get Using the rpi_firmware API as intended allows proper reference counting of the firmware device and means we can remove a downstream patch to the firmware driver. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use DT to configure logging Retrieve the system timer base address directly from DT. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Fail gracefully with bad dtb The logging timestamps depend on the existence of a bcm2835-system-timer node. If this node doesn't exist, leave the logging disabled rather than crashing. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Feb 10, 2025
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: Noralf 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: Noralf 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: Noralf 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: Noralf 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: #1327 Signed-off-by: Phil 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: #2350 Signed-off-by: Phil 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: #2728 Signed-off-by: Phil 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Lukas 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: Phil Elwell <phil@raspberrypi.org> Add missing dma_unmap_sg calls to free relevant swiotlb bounce buffers. This prevents DMA leaks. Signed-off-by: Yaroslav 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: Yaroslav Rosomakho <yaroslavros@gmail.com> mmc: sdhci: Silence MMC warnings When the MMC isn't plugged in, the driver will spam the console which is pretty annoying when using NFS. Signed-off-by: Maxime Ripard <maxime@cerno.tech> mmc: sdhci-iproc: Fix vmmc regulators on iProc The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Borrow the implementation from sdhci_arasan_set_power. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-mmc: uninitialized_var is no more Revert "mmc: sdhci-iproc: Fix vmmc regulators on iProc" This reverts commit aed1939. Commit 6c92ae1 ("mmc: sdhci: Introduce sdhci_set_power_and_bus_voltage()") introduced a generic helper that does the same thing so use that instead in the following commit. Signed-off-by: Juerg Haefliger <juergh@canonical.com> mmc: sdhci-iproc: Fix vmmc regulators (pre-bcm2711) The Linux support for controlling card power via regulators appears to be contentious. I would argue that the default behaviour is contrary to the SDHCI spec - turning off the power writes a reserved value to the SD Bus Voltage Select field of the Power Control Register, which seems to kill the Arasan/iProc controller - but fortunately there is a hook in sdhci_ops to override the behaviour. Signed-off-by: Juerg Haefliger <juergh@canonical.com> Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-mmc: Honor return value of mmc_of_parse() bcm2835_mmc_probe() ignores errors returned by mmc_of_parse() and in particular ignores -EPROBE_DEFER, which may be returned if the power sequencing driver configured in the devicetree is compiled as a module. The user-visible result is that access to the SDIO device fails because its power sequencing requirements have not been observed. Fix it. Signed-off-by: Lukas Wunner <lukas@wunner.de> bcm2835-mmc: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix
pushed a commit
that referenced
this issue
Feb 10, 2025
BCM2835 has two SD card interfaces. This driver uses the other one. bcm2835-sdhost: Error handling fix, and code clarification bcm2835-sdhost: 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 sdhost interface is restricted to integer divisions of core_freq, and the highest sensible option for a core_freq of 250MHz is 84 (250/3 = 83.3MHz), the next being 125 (250/2) which is much too high. Use at your own risk. bcm2835-sdhost: Round up the overclock, so 62 works for 62.5Mhz Also only warn once for each overclock setting. bcm2835-sdhost: Improve error handling and recovery 1) Expose the hw_reset method to the MMC framework, removing many internal calls by the driver. 2) Reduce overclock setting on error. 3) Increase timeout to cope with high capacity cards. 4) Add properties and parameters to control pio_limit and debug. 5) Reduce messages at probe time. bcm2835-sdhost: Further improve overclock back-off bcm2835-sdhost: Clear HBLC for PIO mode Also update pio_limit default in overlay README. bcm2835-sdhost: Add the ERASE capability See: #1076 bcm2835-sdhost: Ignore CRC7 for MMC CMD1 It seems that the sdhost interface returns CRC7 errors for CMD1, which is the MMC-specific SEND_OP_COND. Returning these errors to the MMC layer causes a downward spiral, but ignoring them seems to be harmless. bcm2835-mmc/sdhost: Remove ARCH_BCM2835 differences The bcm2835-mmc driver (and -sdhost driver that copied from it) contains code to handle SDIO interrupts in a threaded interrupt handler rather than waking the MMC framework thread. The change follows a patch from Russell King that adds the facility as the preferred way of working. However, the new code path is only present in ARCH_BCM2835 builds, which I have taken to be a way of testing the waters rather than making the change across the board; I can't see any technical reason why it wouldn't be enabled for MACH_BCM270X builds. So this patch standardises on the ARCH_BCM2835 code, removing the old code paths. bcm2835-sdhost: Don't log timeout errors unless debug=1 The MMC card-discovery process generates timeouts. This is expected behaviour, so reporting it to the user serves no purpose. Suppress the reporting of timeout errors unless the debug flag is on. bcm2835-sdhost: Add workaround for odd behaviour on some cards For reasons not understood, the sdhost driver fails when reading sectors very near the end of some SD cards. The problem could be related to the similar issue that reading the final sector of any card as part of a multiple read never completes, and the workaround is an extension of the mechanism introduced to solve that problem which ensures those sectors are always read singly. bcm2835-sdhost: Major revision This is a significant revision of the bcm2835-sdhost driver. It improves on the original in a number of ways: 1) Through the use of CMD23 for reads it appears to avoid problems reading some sectors on certain high speed cards. 2) Better atomicity to prevent crashes. 3) Higher performance. 4) Activity logging included, for easier diagnosis in the event of a problem. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Restore ATOMIC flag to PIO sg mapping Allocation problems have been seen in a wireless driver, and this is the only change which might have been responsible. SQUASH: bcm2835-sdhost: Only claim one DMA channel With both MMC controllers enabled there are few DMA channels left. The bcm2835-sdhost driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Workaround for "slow" sectors Some cards have been seen to cause timeouts after certain sectors are read. This workaround enforces a minimum delay between the stop after reading one of those sectors and a subsequent data command. Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will not be penalised by this workaround. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Firmware manages the clock divisor The bcm2835-sdhost driver hands control of the CDIV clock divisor register to matching firmware, allowing it to adjust to a changing core clock. This removes the need to use the performance governor or to enable io_is_busy on the on-demand governor in order to get the best SD performance. N.B. As SD clocks must be an integer divisor of the core clock, it is possible that the SD clock for "turbo" mode can be different (even lower) than "normal" mode. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Reset the clock in task context Since reprogramming the clock can now involve a round-trip to the firmware it must not be done at atomic context, and a tasklet is not a task. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Don't exit cmd wait loop on error The FAIL flag can be set in the CMD register before command processing is complete, leading to spurious "failed to complete" errors. This has the effect of promoting harmless CRC7 errors during CMD1 processing into errors that can delay and even prevent booting. Also: 1) Convert the last KERN_ERROR message in the register dumping to KERN_INFO. 2) Remove an unnecessary reset call from bcm2835_sdhost_add_host. See: #1492 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: mmc_card_blockaddr fix Get the definition of mmc_card_blockaddr from drivers/mmc/core/card.h. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: New timer API mmc: bcm2835-sdhost: Support underclocking Support underclocking of the SD bus in two ways: 1. using the max-frequency DT property (which currently has no DT parameter), and 2. using the exiting sd_overclock parameter. The two methods differ slightly - in the former the MMC subsystem is aware of the underclocking, while in the latter it isn't - but the end results should be the same. See: #2350 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Add include highmem.h (needed for kmap_atomic) is pulled in by one of the other include files, but only with some CONFIG settings. Make the inclusion explicit to cater for cases where the CONFIG setting is absent. See: #2366 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc/bcm2835-sdhost: 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: #2728 Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Fix warnings on arm64 Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Allow for sg entries that cross pages The dma_complete handling code calculates a virtual address for a page then adds an offset, but if the offset is more than a page and HIGHMEM is in use then the summed address could be in an unmapped (or just incorrect) page. The upstream SDHOST driver allows for this possibility - copy the code that does so. Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Fix DMA channel leak on error/remove Signed-off-by: Phil Elwell <phil@raspberrypi.org> mmc: bcm2835-sdhost: Support 64-bit physical addresses Signed-off-by: Phil Elwell <phil@raspberrypi.org> bcm2835-sdhost: Replace obsolete struct timeval struct timeval has been retired due to the impending linux 32-bit tv_sec rollover (only 18 years to go) - timespec64 is the obvious replacement. Signed-off-by: Phil Elwell <phil@raspberrypi.com> mmc: sdhost: Pass DT pointer to rpi_firmware_get Using the rpi_firmware API as intended allows proper reference counting of the firmware device and means we can remove a downstream patch to the firmware driver. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use DT to configure logging Retrieve the system timer base address directly from DT. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Use phys addresses for slave DMA config Contrary to what struct snd_dmaengine_dai_dma_data suggests, the configuration of addresses of DMA slave interfaces should be done in CPU physical addresses. Signed-off-by: Phil Elwell <phil@raspberrypi.com> bcm2835-sdhost: Fail gracefully with bad dtb The logging timestamps depend on the existence of a bcm2835-system-timer node. If this node doesn't exist, leave the logging disabled rather than crashing. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The DT bindings for MMC interfaces include a "max-frequency" property that is intended to limit SD bus clock speeds, but neither the bcm2835-sdhost driver nor the bcm2835-mmc driver honour this property.
In the same vein, there is no reason why the sdhost driver couldn't allow the overclock mechanism to also permit underclocking.
See https://www.raspberrypi.org/forums/viewtopic.php?f=107&t=203156.
The text was updated successfully, but these errors were encountered: