mmc: Wait for card_busy before starting sdio requests
Subsystems (2)
cover mmc: Wait for card_busy before starting sdio requests
Hi Ulf,
As discussed before here is a series to make the mmc core check the card_busy op before submitting sdio-rw commands to the host driver.
Not sure if this is what you've in mind, but it is a start :)
This series is RFC because currently I'm travelling, and I do not have any sunxi hardware with the sdio wifi which needs this with me, so I have not been able to test that this set actually fixes things. Given previous tests it is likely that it will though.
A review would be appreciated then I can address any remarks you've before sending a non RFC version.
Regards,
Hans
RFC PATCH 1/3 mmc: Add mmc_is_io_op helper function
Add a helper function to check if an opcode is a sd-io-rw-* opcode.
--- drivers/mmc/core/sdio_ops.h | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/mmc/core/sdio_ops.h +7 -0
@@ -12,6 +12,8 @@#ifndef _MMC_SDIO_OPS_H#define _MMC_SDIO_OPS_H +#include <linux/mmc/sdio.h> +int mmc_send_io_op_cond (struct mmc_host *host,u32 ocr,u32 *rocr);int mmc_io_rw_direct (struct mmc_card *card,int write,unsigned fn,unsigned addr,u8 in,u8 * out);
@@ -19,5 +21,10 @@ int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn, unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz);int sdio_reset (struct mmc_host *host); +static inline bool mmc_is_io_op (u32 opcode) +{ +return opcode ==SD_IO_RW_DIRECT || opcode ==SD_IO_RW_EXTENDED ; +} +#endif
Signature · 1 line
2.4.3
RFC PATCH 2/3 mmc: Wait for card_busy before starting sdio requests
In reply to Hans de GoedeSome sdio wifi chips will not work properly if we try to start new sdio-rw requests while the device is signalling that it is busy.
--- drivers/mmc/core/core.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/mmc/core/core.c +17 -0
@@ -204,6 +204,23 @@ static void __mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)return ; } +/* +* For sdio rw commands we must wait for card busy otherwise some +* sdio devices won't work properly. +*/ +if (mmc_is_io_op (mrq->cmd->opcode) && host->ops->card_busy) { +int tries =500 ;/* Wait aprox 500ms at maximum */ + +while (host->ops->card_busy (host) && --tries) +mmc_delay (1 ); + +if (tries ==0 ) { + mrq->cmd->error = -EBUSY ; +mmc_request_done (host, mrq); +return ; + } + } + host->ops->request (host, mrq); }
Signature · 1 line
2.4.3
RFC PATCH 3/3 mmc: sunxi: Add card busy detection
In reply to Hans de GoedeSome sdio wifi modules have not been working reliable with the sunxi-mmc host code. This turns out to be caused by starting new io-rw commands while the card signals that it is still busy processing a previous command.
This commit adds card-busy detection to the sunxi-mmc driver which together with recent core changes to check card-busy before starting io-rw commands fixes the wifi reliability issues on the Cubietruck and other sunxi boards using sdio wifi.
---
Changes in v2:
-Properly accredit Eugene K for coming up with the fix for this Changes in v3:
-Add card-busy detection and let the core decide when to actually use
card-busy the added detection
--- drivers/mmc/host/sunxi-mmc.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/mmc/host/sunxi-mmc.c +8 -0
@@ -868,6 +868,13 @@ static void sunxi_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)spin_unlock_irqrestore (&host->lock, iflags); } +static int sunxi_mmc_card_busy (struct mmc_host *mmc) +{ +struct sunxi_mmc_host *host =mmc_priv (mmc); + +return !!(mmc_readl (host,REG_STAS ) &SDXC_CARD_DATA_BUSY ); +} +static const struct of_device_id sunxi_mmc_of_match[] = { { .compatible ="allwinner,sun4i-a10-mmc" , }, { .compatible ="allwinner,sun5i-a13-mmc" , },
@@ -882,6 +889,7 @@ static struct mmc_host_ops sunxi_mmc_ops = { .get_cd = mmc_gpio_get_cd, .enable_sdio_irq = sunxi_mmc_enable_sdio_irq, .hw_reset = sunxi_mmc_hw_reset, + .card_busy = sunxi_mmc_card_busy, }; static int sunxi_mmc_resource_request(struct sunxi_mmc_host *host,
Signature · 1 line
2.4.3