Merge branch 'linux-linaro-lsk-v4.4' into linux-linaro-lsk-v4.4-android
[firefly-linux-kernel-4.4.55.git] / drivers / mmc / core / core.c
index 9c9bd3c906375c59669dbef7f99616ffd316bab1..4df0c68e87e8a81a34b052e924c5ffae32bb3d34 100644 (file)
@@ -29,7 +29,9 @@
 #include <linux/random.h>
 #include <linux/slab.h>
 #include <linux/of.h>
-#include <linux/wakelock.h>
+
+#define CREATE_TRACE_POINTS
+#include <trace/events/mmc.h>
 
 #include <linux/mmc/card.h>
 #include <linux/mmc/host.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 +64,6 @@
 #define MMC_BKOPS_MAX_TIMEOUT  (4 * 60 * 1000) /* max time to wait in ms */
 
 static struct workqueue_struct *workqueue;
-static struct wake_lock mmc_delayed_work_wake_lock;
 static const unsigned freqs[] = { 400000, 300000, 200000, 100000 };
 
 /*
@@ -74,7 +80,6 @@ module_param(use_spi_crc, bool, 0);
 static int mmc_schedule_delayed_work(struct delayed_work *work,
                                     unsigned long delay)
 {
-       wake_lock(&mmc_delayed_work_wake_lock);
        return queue_delayed_work(workqueue, work, delay);
 }
 
@@ -178,6 +183,7 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
                        pr_debug("%s:     %d bytes transferred: %d\n",
                                mmc_hostname(host),
                                mrq->data->bytes_xfered, mrq->data->error);
+                       trace_mmc_blk_rw_end(cmd->opcode, cmd->arg, mrq->data);
                }
 
                if (mrq->stop) {
@@ -620,8 +626,12 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host,
                }
        }
 
-       if (!err && areq)
+       if (!err && areq) {
+               trace_mmc_blk_rw_start(areq->mrq->cmd->opcode,
+                                      areq->mrq->cmd->arg,
+                                      areq->mrq->data);
                start_err = __mmc_start_data_req(host, areq->mrq);
+       }
 
        if (host->areq)
                mmc_post_req(host, host->areq->mrq, 0);
@@ -877,11 +887,11 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card)
        /*
         * Some cards require longer data read timeout than indicated in CSD.
         * Address this by setting the read timeout to a "reasonably high"
-        * value. For the cards tested, 300ms has proven enough. If necessary,
+        * value. For the cards tested, 600ms has proven enough. If necessary,
         * this value can be increased if other problematic cards require this.
         */
        if (mmc_card_long_read_time(card) && data->flags & MMC_DATA_READ) {
-               data->timeout_ns = 300000000;
+               data->timeout_ns = 600000000;
                data->timeout_clks = 0;
        }
 
@@ -2058,8 +2068,13 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from,
        struct mmc_command cmd = {0};
        unsigned int qty = 0;
        unsigned long timeout;
+       unsigned int fr, nr;
        int err;
 
+       fr = from;
+       nr = to - from + 1;
+       trace_mmc_blk_erase_start(arg, fr, nr);
+
        mmc_retune_hold(card->host);
 
        /*
@@ -2166,6 +2181,7 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from,
                 (R1_CURRENT_STATE(cmd.resp[0]) == R1_STATE_PRG));
 out:
        mmc_retune_release(card->host);
+       trace_mmc_blk_erase_end(arg, fr, nr);
        return err;
 }
 
@@ -2569,7 +2585,6 @@ void mmc_rescan(struct work_struct *work)
        struct mmc_host *host =
                container_of(work, struct mmc_host, detect.work);
        int i;
-       bool extend_wakelock = false;
 
        if (host->trigger_card_event && host->ops->card_event) {
                host->ops->card_event(host);
@@ -2596,12 +2611,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.
@@ -2631,20 +2640,14 @@ void mmc_rescan(struct work_struct *work)
 
        mmc_claim_host(host);
        for (i = 0; i < ARRAY_SIZE(freqs); i++) {
-               if (!mmc_rescan_try_freq(host, max(freqs[i], host->f_min))) {
-                       extend_wakelock = true;
+               if (!mmc_rescan_try_freq(host, max(freqs[i], host->f_min)))
                        break;
-               }
                if (freqs[i] <= host->f_min)
                        break;
        }
        mmc_release_host(host);
 
  out:
-       if (extend_wakelock)
-               wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);
-       else
-               wake_unlock(&mmc_delayed_work_wake_lock);
        if (host->caps & MMC_CAP_NEEDS_POLL)
                mmc_schedule_delayed_work(&host->detect, HZ);
 }
@@ -2872,9 +2875,6 @@ static int __init mmc_init(void)
        if (!workqueue)
                return -ENOMEM;
 
-       wake_lock_init(&mmc_delayed_work_wake_lock, WAKE_LOCK_SUSPEND,
-                      "mmc_delayed_work");
-
        ret = mmc_register_bus();
        if (ret)
                goto destroy_workqueue;
@@ -2895,7 +2895,6 @@ unregister_bus:
        mmc_unregister_bus();
 destroy_workqueue:
        destroy_workqueue(workqueue);
-       wake_lock_destroy(&mmc_delayed_work_wake_lock);
 
        return ret;
 }
@@ -2906,7 +2905,6 @@ static void __exit mmc_exit(void)
        mmc_unregister_host_class();
        mmc_unregister_bus();
        destroy_workqueue(workqueue);
-       wake_lock_destroy(&mmc_delayed_work_wake_lock);
 }
 
 subsys_initcall(mmc_init);