mmc: core: don't check card status when flushing cache
[firefly-linux-kernel-4.4.55.git] / drivers / mmc / core / core.c
index 96666984a103893e720637201a91c97790e44048..44432229acc57aa686bd26d2e9046f224d893480 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/slab.h>
 #include <linux/of.h>
 
+#define CREATE_TRACE_POINTS
 #include <trace/events/mmc.h>
 
 #include <linux/mmc/card.h>
 #include "sd_ops.h"
 #include "sdio_ops.h"
 
+EXPORT_TRACEPOINT_SYMBOL_GPL(mmc_blk_erase_start);
+EXPORT_TRACEPOINT_SYMBOL_GPL(mmc_blk_erase_end);
+EXPORT_TRACEPOINT_SYMBOL_GPL(mmc_blk_rw_start);
+EXPORT_TRACEPOINT_SYMBOL_GPL(mmc_blk_rw_end);
+
 /* If the device is not responding */
 #define MMC_CORE_TIMEOUT_MS    (10 * 60 * 1000) /* 10 minute timeout */
 
@@ -57,7 +63,6 @@
  */
 #define MMC_BKOPS_MAX_TIMEOUT  (4 * 60 * 1000) /* max time to wait in ms */
 
-static struct workqueue_struct *workqueue;
 static const unsigned freqs[] = { 400000, 300000, 200000, 100000 };
 
 /*
@@ -68,21 +73,16 @@ static const unsigned freqs[] = { 400000, 300000, 200000, 100000 };
 bool use_spi_crc = 1;
 module_param(use_spi_crc, bool, 0);
 
-/*
- * Internal function. Schedule delayed work in the MMC work queue.
- */
 static int mmc_schedule_delayed_work(struct delayed_work *work,
                                     unsigned long delay)
 {
-       return queue_delayed_work(workqueue, work, delay);
-}
-
-/*
- * Internal function. Flush all scheduled work from the MMC work queue.
- */
-static void mmc_flush_scheduled_work(void)
-{
-       flush_workqueue(workqueue);
+       /*
+        * We use the system_freezable_wq, because of two reasons.
+        * First, it allows several works (not the same work item) to be
+        * executed simultaneously. Second, the queue becomes frozen when
+        * userspace becomes frozen during system PM.
+        */
+       return queue_delayed_work(system_freezable_wq, work, delay);
 }
 
 #ifdef CONFIG_FAIL_MMC_REQUEST
@@ -1132,6 +1132,11 @@ void mmc_set_initial_state(struct mmc_host *host)
        host->ios.bus_width = MMC_BUS_WIDTH_1;
        host->ios.timing = MMC_TIMING_LEGACY;
        host->ios.drv_type = 0;
+       host->ios.enhanced_strobe = false;
+
+       if ((host->caps2 & MMC_CAP2_HS400_ES) &&
+               host->ops->hs400_enhanced_strobe)
+               host->ops->hs400_enhanced_strobe(host, &host->ios);
 
        mmc_set_ios(host);
 }
@@ -2490,6 +2495,7 @@ static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
         * if the card is being re-initialized, just send it.  CMD52
         * should be ignored by SD/eMMC cards.
         */
+#ifdef MMC_STANDARD_PROBE
        sdio_reset(host);
        mmc_go_idle(host);
 
@@ -2502,7 +2508,26 @@ static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
                return 0;
        if (!mmc_attach_mmc(host))
                return 0;
+#else
+       if (host->restrict_caps & RESTRICT_CARD_TYPE_SDIO)
+               sdio_reset(host);
 
+       mmc_go_idle(host);
+
+       if (host->restrict_caps &
+           (RESTRICT_CARD_TYPE_SDIO | RESTRICT_CARD_TYPE_SD))
+               mmc_send_if_cond(host, host->ocr_avail);
+       /* Order's important: probe SDIO, then SD, then MMC */
+       if ((host->restrict_caps & RESTRICT_CARD_TYPE_SDIO) &&
+           !mmc_attach_sdio(host))
+               return 0;
+       if ((host->restrict_caps & RESTRICT_CARD_TYPE_SD) &&
+            !mmc_attach_sd(host))
+               return 0;
+       if ((host->restrict_caps & RESTRICT_CARD_TYPE_EMMC) &&
+            !mmc_attach_mmc(host))
+               return 0;
+#endif
        mmc_power_off(host);
        return -EIO;
 }
@@ -2605,12 +2630,6 @@ void mmc_rescan(struct work_struct *work)
 
        host->detect_change = 0;
 
-       /* If the card was removed the bus will be marked
-        * as dead - extend the wakelock so userspace
-        * can respond */
-       if (host->bus_dead)
-               extend_wakelock = 1;
-
        /*
         * Let mmc_bus_put() free the bus/bus_ops if we've found that
         * the card is no longer present.
@@ -2682,7 +2701,6 @@ void mmc_stop_host(struct mmc_host *host)
 
        host->rescan_disable = 1;
        cancel_delayed_work_sync(&host->detect);
-       mmc_flush_scheduled_work();
 
        /* clear pm flags now and let card drivers set them as needed */
        host->pm_flags = 0;
@@ -2767,8 +2785,9 @@ int mmc_flush_cache(struct mmc_card *card)
        if (mmc_card_mmc(card) &&
                        (card->ext_csd.cache_size > 0) &&
                        (card->ext_csd.cache_ctrl & 1)) {
-               err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
-                               EXT_CSD_FLUSH_CACHE, 1, 0);
+               err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+                                  EXT_CSD_FLUSH_CACHE, 1, 1,
+                                  true, false, false);
                if (err)
                        pr_err("%s: cache flush error %d\n",
                                        mmc_hostname(card->host), err);
@@ -2871,13 +2890,9 @@ static int __init mmc_init(void)
 {
        int ret;
 
-       workqueue = alloc_ordered_workqueue("kmmcd", 0);
-       if (!workqueue)
-               return -ENOMEM;
-
        ret = mmc_register_bus();
        if (ret)
-               goto destroy_workqueue;
+               return ret;
 
        ret = mmc_register_host_class();
        if (ret)
@@ -2893,9 +2908,6 @@ unregister_host_class:
        mmc_unregister_host_class();
 unregister_bus:
        mmc_unregister_bus();
-destroy_workqueue:
-       destroy_workqueue(workqueue);
-
        return ret;
 }
 
@@ -2904,7 +2916,6 @@ static void __exit mmc_exit(void)
        sdio_unregister_bus();
        mmc_unregister_host_class();
        mmc_unregister_bus();
-       destroy_workqueue(workqueue);
 }
 
 subsys_initcall(mmc_init);