mmc: card: abort the suspend if the card is busy

mmc_blk_suspend() is triggered when system is going into suspend which
then waits for the mmcqd thread (which processes active MMC transfer
requests) to complete all queued transfer requests but if mmcqd has
multiple requests to be processed at this point, mmc_blk_suspend() may
very well sleep for duration longer than DPM (Device Power Management)
timeout (currently 12 sec) causing the DPM timeout bug.

To fix this issue, mmc_blk_suspend() checks if there are any more pending
MMC requests in progress or not and if there are any, it returns error
which should abort the ongoing system suspend.

CRs-Fixed: 439192
Change-Id: I51a31cf43c8da4944617d1c4441a27cc6577926f
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
msm: board-msm7627a-wlan: Fix incorrect wlan regulator cleanup

Wlan regulator handlers which are obtained in qrf6285_init_regs()
should not be freed. Freeing those handler using regulator_put()
would cause power regulator module to access invalid handlers in
sup-sequence power up/down sequence and lead kernel to panic.
This patch removes regulator_put() call in wlan_switch_regulators().

During power down sequence, there are changes in wlan_switch_regulators()
to enter into infinite while loop (ie, index is not decremented for power
down case). Fixed now.

Current wlan_switch_regulators() functions ignores to turn of all wlan
regulator when one of wlan regulator turn off fails. Ideally, it should
try to turn off all wlan related regulators without considering
failures.

GPIO free support is added for msm8625q evbd and skud prime boards and
minor cosmetic changes are covered.

CRs-fixed: 468066
Change-Id: Ia5d99e33046d03256bb9e5a8cd55e1812632ba10
Signed-off-by: Jimmy Chen <jzchen@codeaurora.org>
diag: Add concurrency protection to writes on smd data channels

Currently, diag does not protect against multiple threads writing
on a diag smd data channel at the same time. Make changes to protect
against concurrent writes on the same smd data channel.

CRs-Fixed: 455354

Change-Id: I6892db6ab55c402959b65a1eaad2f985094455ad
Signed-off-by: Dixon Peterson <dixonp@codeaurora.org>
msm: cpr: Bump up nom and turbo Vmin for 1GHz devices

For the 1GHz 8x25V2.0 devices, the minimum voltage
requirement is being raised for floor_fuse=0x3 devices
as per chip characterization team's recommendation.
Nominal Vmin is raised from 1.15V to 1.175V and Turbo
Vmin is raised from 1.15V to 1.2V.

CRs-Fixed: 468601
Change-Id: I867e11aabe4dc2840c614200f5b4f7040f1769e8
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
mmc: core: Don't cancel detect work during MMC suspend

When MMC host is suspending the cancellation of the MMC detect
work is in progress. And mmc_rescan() which had triggered for
SD card is blocked since mmcqd/1 has acquired the host lock.
The mmcqd/1 is waiting to proceed for the card status check.
Meanwhile, a write request is received on eMMC but it cannot
proceed as it is waiting for the ongoing runtime suspend to finish.

"kworker/0:1"
----
-000|need_resched()
-001|schedule_timeout(timeout = 2147483647)
-002|wait_for_common(x = 0xD9391E90, ?, state = 2, iowait = 0)
-003|flush_workqueue(wq = 0xD92DCA80)
-004|mmc_suspend_host(host = 0xD8B20000)
-005|msmsdcc_runtime_suspend(dev = 0xC08B0598)
-006|pm_generic_runtime_suspend(?)
-007|__rpm_callback(cb = 0xC02F1BD8, dev = 0xC08B0598)
-008|rpm_suspend(dev = 0xC08B0598, rpmflags = 2)
-009|pm_runtime_work(work = 0xC08B065C)
-010|process_one_work(worker = 0xD9367F40, work = 0xC08B065C)
-011|worker_thread(__worker = 0xD9367F40)
-012|kthread(_create = 0xD924FF18)
-013|kernel_thread_exit(asm)
 ---|end of frame
    |

"kworker/u:4"
----
-000|need_resched()
-001|__mmc_claim_host(host = 0xD8B21000, abort = 0x0)
-002|mmc_sd_detect(host = 0xD8B21000)
-003|mmc_rescan(work = 0xD8B212A0)
-004|process_one_work(worker = 0xCDB12440, work = 0xD8B212A0)
-005|worker_thread(__worker = 0xCDB12440)
-006|kthread(_create = 0xD8BC7F18)
-007|kernel_thread_exit(asm)
 ---|end of frame
    |

mmcqd/1 (running)
----
-000|need_resched()
-001|schedule_timeout(timeout = 2147483647)
-002|io_schedule_timeout(timeout = 2147483647)
-003|wait_for_common(x = 0xD8633E2C, ?, state = 2, iowait = 1)
-004|mmc_wait_for_req_done(host = 0xD8B21000, mrq = 0xD8633E1C)
-005|mmc_wait_for_cmd(host = 0xD8B21000, cmd = 0xD8633E50, retries = 5)
-006|get_card_status(card = 0xD8D8B800, status = 0xD8633EA4, retries = 5)
-007|mmc_blk_err_check(card = 0xD8D8B800, areq = 0xD8624440)
-008|mmc_start_req(host = 0xD8B21000, areq = 0x0, error = 0xD8633F4C)
-009|mmc_blk_issue_rw_rq(mq = 0xD8624008, ?)
-010|mmc_blk_issue_rq(mq = 0xD8624008, req = 0x0)
-011|mmc_queue_thread(d = 0xD8624008)
-012|kthread(_create = 0xD9397D80)
-013|kernel_thread_exit(asm)
 ---|end of frame
    |

mmcqd/0
----
-000|need_resched()
-001|rpm_resume(dev = 0xC08B0598, rpmflags = 4)
-002|__pm_runtime_resume(dev = 0xC08B0598, rpmflags = 4)
-003|msmsdcc_enable(mmc = 0xD8B20000)
-004|__mmc_claim_host(host = 0xD8B20000, abort = 0x0)
-005|mmc_blk_issue_rq(mq = 0xD8C43008, req = 0xC52C9798)
-006|mmc_queue_thread(d = 0xD8C43008)
-007|kthread(_create = 0xD9397D80)
-008|kernel_thread_exit(asm)
 ---|end of frame
    |

So remove the cancellation of the detect work for the
MMC suspend to proceed and avoid this deadlock.

CRs-Fixed: 471053
Change-Id: Id79d6b81e992b08039d639b1c0f6c2eb4a79df62
Signed-off-by: Pratibhasagar V <pratibha@codeaurora.org>
Merge "msm: cpr: Bump up nom and turbo Vmin for 1GHz devices"
msm: acpuclock-8625q: Raise EBI before Apps frequency

The EBI frequency needs to be raised before raising Apps
frequency. Ideally, not doing this should hog more CPU
but in this case it also helps remove memory related
instability.

CRs-Fixed: 473336
Change-Id: I592bf11b82cea60fc58d2dfcd80b6a8847111e20
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
Acked-by: Gopi Krishna Nedanuri <gnedanur@qti.qualcomm.com>

Signed-off-by: Goberu Gopal <ggober@codeaurora.org>
Merge "msm: acpuclock-8625q: Raise EBI before Apps frequency"
Merge "mmc: card: abort the suspend if the card is busy"
Merge "mmc: core: Don't cancel detect work during MMC suspend"
Merge "diag: Add concurrency protection to writes on smd data channels"
msm: kgsl: Don't change the sglen of the memdesc if allocation fails

If the page_alloc loop fails, we changed the length of the scatterlist
for the memdesc to the last good page so we could have an efficient
loop through kgsl_sharedmem_free.  Unfortunately, we were also using
the sglen to decide between using kmem or vmalloc memory for the sg
list in the first place. There is a chance that one could start out
with a large sg list from vmalloc, but if it failed early, then we
could truncate the size and attempt to kfree it.

Zero the stlist at init time and use a length == 0 as an indicator
that the list might be truncated.

Change-Id: Ic0dedbadc0007b5e3c338151517c95999ed523a3
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Vinay Roy <vroy@codeaurora.org>
msm: kgsl: Properly record the size of the sglist in the memdesc

It was possible to fail out of kgsl_sharedmem_alloc after a sglist was
allocated but before we saved the size of the allocation which caused
problems when the sglist was freed during cleanup.

CRs-fixed: 464289
Change-Id: I597c671b7a69d2b7930d426884cdfb6799714763
Signed-off-by: Vinay Roy <vroy@codeaurora.org>
Merge "msm: kgsl: Don't change the sglen of the memdesc if allocation fails"
Merge "msm: kgsl: Properly record the size of the sglist in the memdesc"
msm: acpuclock: Set the frequency to 700Mhz just before reboot

Set the frequency to 700Mhz just before the reboot so that
we are at the nominal frequency.

Change-Id: I1f007ad28fbe593d83026e1e02eba9765fa0cf24
Signed-off-by: Trilok Soni <tsoni@codeaurora.org>
Signed-off-by: Tirupathi Reddy <tirupath@codeaurora.org>
Merge "msm: acpuclock: Set the frequency to 700Mhz just before reboot"
Merge "msm: board-msm7627a-wlan: Fix incorrect wlan regulator cleanup"
hrtimer: Consider preemption when migrating hrtimer cpu_bases

When switching to a new cpu_base in switch_hrtimer_base(), we
briefly enable preemption by unlocking the cpu_base lock in two
places. During this interval it's possible for the running thread
to be swapped to a different CPU.

Consider the following example:

CPU #0                                 CPU #1
----                                   ----
hrtimer_start()                        ...
 lock_hrtimer_base()
 switch_hrtimer_base()
  this_cpu = 0;
  target_cpu_base = 0;
  raw_spin_unlock(&cpu_base->lock)
<migrate to CPU 1>
...                                    this_cpu == 0
                                       cpu == this_cpu
                                       timer->base = CPU #0
                                       timer->base != LOCAL_CPU

Since the cached this_cpu is no longer accurate, we'll skip the
hrtimer_check_target() check. Once we eventually go to program
the hardware, we'll decide not to do so since it knows the real
CPU that we're running on is not the same as the chosen base. As
a consequence, we may end up missing the hrtimer's deadline.

Fix this by updating the local CPU number each time we retake a
cpu_base lock in switch_hrtimer_base().

Another possibility is to disable preemption across the whole of
switch_hrtimer_base.  This looks suboptimal since preemption
would be disabled while waiting for lock(s).

CRs-Fixed: 477127
Change-Id: I3f76d528ab2288ef5f950f4d048e7f3fa6cf1228
Signed-off-by: Michael Bohan <mbohan@codeaurora.org>
hrtimer: Prevent enqueue of hrtimer on dead CPU

When switching the hrtimer cpu_base, we briefly allow for
preemption to become enabled by unlocking the cpu_base lock.
During this time, the CPU corresponding to the new cpu_base
that was selected may in fact go offline. In this scenario, the
hrtimer is enqueued to a CPU that's not online, and therefore
it never fires.

As an example, consider this example:

CPU #0                          CPU #1
----                            ----
...                             hrtimer_start()
                                 lock_hrtimer_base()
                                 switch_hrtimer_base()
                                  cpu = hrtimer_get_target() -> 1
                                  spin_unlock(&cpu_base->lock)
                                <migrate thread to CPU #0>
                                <offline>
spin_lock(&new_base->lock)
this_cpu = 0
cpu != this_cpu
enqueue_hrtimer(cpu_base #1)

To prevent this scenario, verify that the CPU corresponding to
the new cpu_base is indeed online before selecting it in
hrtimer_switch_base(). If it's not online, fallback to using the
base of the current CPU.

CRs-Fixed: 477129
Change-Id: I6359cb299ba7e08abf25d3360fcdd925b4c03b69
Signed-off-by: Michael Bohan <mbohan@codeaurora.org>