OSDN Git Service

sagit-ice-cold/kernel_xiaomi_msm8998.git
8 years agoscsi: ufs: Change power mode at run-time via debug-fs
Gilad Broner [Tue, 4 Mar 2014 15:40:54 +0000 (17:40 +0200)]
scsi: ufs: Change power mode at run-time via debug-fs

Add 'power_mode' entry to UFS debug-fs to allow query of current
power mode status and changing the power mode by writing to the
entry a string in the format 'GGLLMM' where:
G - selected gear
L - number of lanes
M - power mode
    (1=fast mode, 2=slow mode, 4=fast-auto mode, 5=slow-auto mode)
First letter is for RX, second is for TX.

Change-Id: Ia48cb2719bb11e66bca923c5f4647a33cbd6c43e
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[gbroner@codeaurora.org: fix merge conflicts]
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[subhashj@codeaurora.org: resolved merge conflicts and compilation error]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
8 years agoscsi: ufs: Add sysfs node to dynamically control clock scaling
Sahitya Tummala [Thu, 27 Mar 2014 10:21:56 +0000 (15:51 +0530)]
scsi: ufs: Add sysfs node to dynamically control clock scaling

Provide an option to enable/disable clock scaling during runtime.
Write 1/0 to "clkscale_enable" sysfs node to enable/disable clock
scaling.

Change-Id: I67a6cd317d3dca97a992e240c970719f85067cd8
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: add debug counters for recoverable errors during runtime
Yaniv Gardi [Tue, 15 Apr 2014 19:50:44 +0000 (22:50 +0300)]
scsi: ufs: add debug counters for recoverable errors during runtime

There is no way to know how many times various UFS errors happened
while system is running if we have successfully recovered from those
errors. Those failures should be counted and inspected as they might be
anomaly behavior of the driver and can impact performance.
This change adds support to capture these failures statistics like how
many times we have seen errors, and which type of errors.

To reset the counters:
echo 1 > /sys/kernel/debug/ufs/err_stats

To print them out:
cat /sys/kernel/debug/ufs/err_stats

Note: There is no need to enable them as they are never disabled.
This error counters are something that we always would like to have.

Change-Id: I559c729b998f79c6bdda2da54c0f0ec7531696d7
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: cleanup unused quirks
Subhash Jadavani [Sun, 6 Apr 2014 07:46:44 +0000 (10:46 +0300)]
scsi: ufs: cleanup unused quirks

We had added many host and device quirks support non commercial UFS device
and UFS controller. As these quirks are not required in commercially
available UFS devices and UFS controller, we should offload driver from
maintaining these unused quirks.

Change-Id: If721d71b41e19e6c68af49403a0043bf40266ffa
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
Signed-off-by: Raviv Shvili <rshvili@codeaurora.org>
[gbroner@codeaurora.org: fix merge conflict]
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
8 years agoscsi: ufs: Add sysfs node to dynamically control clock gating
Sahitya Tummala [Fri, 28 Mar 2014 04:12:09 +0000 (09:42 +0530)]
scsi: ufs: Add sysfs node to dynamically control clock gating

Provide an option to enable/disable clock gating during runtime.
Write 1 or 0 to "clkgate_enable" sysfs node to enable/disable
clock gating.

Change-Id: I69a20e66cf91bb889ac3942eb2d20d5adc289d03
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: seperate device and host quirks
Raviv Shvili [Tue, 1 Apr 2014 19:20:15 +0000 (22:20 +0300)]
scsi: ufs: seperate device and host quirks

Currently we use the host quirks mechanism in order to
handle both device and host controller quirks.
In order to support many UFS devices we should separate
handling the device quirks from the host controller's.

Change-Id: I6c23be42ff78689f9aad4d5c0c9f0a678bfb5c14
Signed-off-by: Raviv Shvili <rshvili@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
8 years agoscsi: ufs: add read string descriptor api
Raviv Shvili [Sun, 30 Mar 2014 10:36:05 +0000 (13:36 +0300)]
scsi: ufs: add read string descriptor api

The string descriptor may consist of up to 126 UNICODE characters.
The number of UNICODE characters is calculated
by (descriptor's length - 2)/2.
In addition the api allows to get the result in an ascii format.

Change-Id: If43453bf5f9a826900c0acc064e8def275c0f7d1
Signed-off-by: Raviv Shvili <rshvili@codeaurora.org>
8 years agoscsi: ufs: add descriptor read support
Raviv Shvili [Thu, 20 Mar 2014 19:33:04 +0000 (21:33 +0200)]
scsi: ufs: add descriptor read support

Allow reading descriptors with length which is different
than the descriptors max size.

Change-Id: Ia0685ae147883f33466865d2348d71473e0d5173
Signed-off-by: Raviv Shvili <rshvili@codeaurora.org>
8 years agoscsi: ufs: add additional tracing messages
Subhash Jadavani [Thu, 20 Mar 2014 22:52:09 +0000 (15:52 -0700)]
scsi: ufs: add additional tracing messages

This patch adds following tracing messages:
 - Add support to trace the automatic background operations enable/disable
   events.
 - Add addition logs to trace the UFS device and UFS link state during
   suspend/resume and initialization.

Change-Id: I732b255296042442e50278c2700c52bd166e1d8b
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: remove UFSHCD_BROKEN_LCC_PROCESSING_ON_DEVICE quirk
Subhash Jadavani [Thu, 20 Mar 2014 19:46:14 +0000 (12:46 -0700)]
scsi: ufs-msm: remove UFSHCD_BROKEN_LCC_PROCESSING_ON_DEVICE quirk

New commercial UFS devices don't have the issues with LCC processing
but UFS host controller might still have the issue with LCC processing
hence keep the UFSHCD_BROKEN_LCC_PROCESSING_ON_HOST quirk enabled but
disable the UFSHCD_BROKEN_LCC_PROCESSING_ON_DEVICE quirk.

Change-Id: Ib3d563553878eec39c677f38af1545f470e8ee9b
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: split broken LCC quirk
Subhash Jadavani [Thu, 20 Mar 2014 19:41:53 +0000 (12:41 -0700)]
scsi: ufs: split broken LCC quirk

Currently when UFSHCD_BROKEN_LCC quirk is defined, LCC is getting
disabled on both host and device side but there could be a need
where we don't want to disable the LCC on both side hence this change
splits the quirk in 2 parts one for host and one for device.

Change-Id: I906a24a428665e3ee67a4c2ec3fc31f47e5c7e3c
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
8 years agoscsi: ufs-msm: allow background operations during runtime suspend
Subhash Jadavani [Thu, 20 Mar 2014 22:42:42 +0000 (15:42 -0700)]
scsi: ufs-msm: allow background operations during runtime suspend

Allow the card to perform background operations during runtime suspend.

Change-Id: Ie93b4ad795f7afb05addb551f73fca853ecd4769
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoRevert "scsi: ufs: try read capacity (10) first"
Dolev Raviv [Thu, 20 Mar 2014 09:21:56 +0000 (11:21 +0200)]
Revert "scsi: ufs: try read capacity (10) first"

This reverts commit 7d76a33cac7040f3e05c1a49fc312e53dc3b2f1c.
Read capacity (16) is used, in addition to reading capacity, for
reading unmap command parameters. In UFS spec since v2.0 read
capacity (16) command is mandatory for embedded devices.

If read capacity (16) is not supported by the device then it simply
rejects the scsi command with ILLEGAL_REQUEST in sense key. The sd
driver then retries with read capacity (10), thus keeping backward
compatibility.

Change-Id: Iaa2acdfab0d7f0f6e1ef20e370195a3b64068216
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
8 years agoscsi: ufshcd: fix one of the argument type for ufshcd_query_descriptor
Subhash Jadavani [Sat, 1 Mar 2014 09:18:22 +0000 (01:18 -0800)]
scsi: ufshcd: fix one of the argument type for ufshcd_query_descriptor

ufshcd_query_descriptor() function should take the descriptor id as one of
its argument but type of this argument is incorrect, hence fix it here.

Change-Id: If83b551b2bc4da644d03a0ae37b2e83dc7909b43
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[gbroner@codeaurora.org: fix merge conflicts and add missing
function signatures]
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: probe UFS only if it is the boot device
Subhash Jadavani [Tue, 25 Feb 2014 08:55:10 +0000 (00:55 -0800)]
scsi: ufs-msm: probe UFS only if it is the boot device

Boot device can be either UFS or eMMC which means if eMMC is the boot
device, probing UFS device is not desirable as it's not going to be
used after probing. Kernel command line parameter "android.bootdevice"
tells the kernel about the boot device so look at this boot device
parameter to know whether to probe UFS device or not.

Change-Id: I053b9611088263cd8de64085754c00d082aec3ed
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufshcd: release resources if probe fails
Subhash Jadavani [Wed, 26 Feb 2014 05:43:07 +0000 (21:43 -0800)]
scsi: ufshcd: release resources if probe fails

If ufshcd pltfrm/pci driver's probe fails for some reason then ensure that
scsi host is released to avoid memory leak but managed memory allocations
(via devm_* calls) need not to be freed explicitly on probe failure as
memory allocated with these functions is automatically freed on driver
detach.

Change-Id: Ic88c3e1d29a6b03e9a79201d3790f26bc4ccae61
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[gbroner@codeaurora.org: fix minor merge conflicts]
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
8 years agoscsi: ufs-msm: enable power management
Subhash Jadavani [Fri, 14 Feb 2014 01:39:28 +0000 (17:39 -0800)]
scsi: ufs-msm: enable power management

Until now due to issues with UFS host controller (especially with version
1.1.0) and UFS device, UFS power management was not enabled but now as UFS
link hibernate and UFS device sleep functionalities are stable, we are
enabling the level 3 power management which puts UFS link in hibernate and
UFS device in sleep state during suspend.

Change-Id: I0376bb3bfa47f4fa13527f496258862f10ffe07a
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: avoid full UFS initialization on system resume
Subhash Jadavani [Thu, 13 Feb 2014 19:50:37 +0000 (11:50 -0800)]
scsi: ufs-msm: avoid full UFS initialization on system resume

As part of UFS power management, UFS link would be put in hibernate and
UFS device would be put in SLEEP mode as part of runtime/system suspend
callback. But when system goes into suspend with VDD minimization, UFS
PHY states are being reset which means UFS link hibernate exit command on
system resume would fail. There are 2 ways to workaround this issue, one
is to reinitialize the entire UFS link on system resume but it has very
high latency of ~150ms whereas other acceptable workaround is to save
the UFS PHY state information before system goes into suspend and restore
this state information during system resume but before executing the
hibernate exit command. This change implements the 2nd workaround.

Change-Id: I061871321b9c0e6386188355858217dcedd4f20a
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
[subhashj@codeaurora.org: resolved merge conflicts, dropped changes to
ufshcd.c & unipro.h]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: increase the query request timeout
Subhash Jadavani [Thu, 23 Jan 2014 01:54:12 +0000 (17:54 -0800)]
scsi: ufs: increase the query request timeout

Some of the query requests like reading the fDeviceInit flag
and reading the ref_clk attribute could take more than current
timeout value of 30ms and hence we might see error messages
printed in kernel logs even though next retries are going to
succeed. Hence its better to increase the query request timeout
to 100ms which seems good enough for all query requests to be
completed.

Change-Id: I57ed50e25131677ee6cab6b63ccacf7020f2b501
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: inform PHY about analog rails power down
Subhash Jadavani [Fri, 10 Jan 2014 22:23:52 +0000 (14:23 -0800)]
scsi: ufs-msm: inform PHY about analog rails power down

UFS PHY analog rails (VDDA_PHY_0P9 & VDDA_PLL_1P8) can be power collapsed
while the UFS link is in hibern8 state but PHY needs to be informed about
the power collapse by writing 0 to its power down control register. If PHY
is not informed about it, hibern8 exit might fail. This fixes this problem.

Change-Id: If897681569ca0073f2075acf8a9014da8d762827
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: enable quirk to fix gear change to HS
Yaniv Gardi [Wed, 12 Feb 2014 05:44:43 +0000 (21:44 -0800)]
scsi: ufs-msm: enable quirk to fix gear change to HS

With the G3 UFS devices, changing gear into HS is failing.
The quirk solves the problem of changing gear into HS by enabling
the attribute that specifies whether or not the inbound Link supports
unterminated line in HS mode.
This change enables the quirk.

Change-Id: I2a2fcb9dd0233e4dee7cc2443b6a60808e62da7c
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: fix multiple ufs spec violation
Dolev Raviv [Wed, 12 Feb 2014 08:25:13 +0000 (10:25 +0200)]
scsi: ufs: fix multiple ufs spec violation

When a command to a W-LU is timed out via scsi, error handling
will treat it as any other LU and send commands such as
START_STOP with wrong format or task abort. Those commands are
illegal for W-LU according to the UFS spec.
To solve it, when an error is recognized those steps are skipped
and the last step, reset and restore process, is initiated.

Change-Id: I7ff2a8d3c816adf5e1bf3762c0a6c342be7e83ea
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
8 years agoscsi: ufs-msm: change default working mode in HS to rate A
Yaniv Gardi [Wed, 12 Feb 2014 01:13:33 +0000 (17:13 -0800)]
scsi: ufs-msm: change default working mode in HS to rate A

So far, we used to work in the maximum HS (High Speed) rate available
by the UFS device (and supported by the controller) which is rate B.
This change changes the default working rate from rate B to rate A,
in order to gain more stability.

Change-Id: I797485b9699c5dab2a294b524f27c8e327b1e62d
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs-msm: add PHY calibration values for UFS controller 1.1.1
Yaniv Gardi [Wed, 15 Jan 2014 21:34:34 +0000 (23:34 +0200)]
scsi: ufs-msm: add PHY calibration values for UFS controller 1.1.1

The PHY should be calibrated with set of values based on the UFS
controller revision.
In this patch the UFS controller revision is read, and based on it,
it is decided which set of values to use in order to calibrate the PHY.

Change-Id: I369f9332df95364ee9e2ed83c8ce1bf5a28565c0
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: disable LCC configuration in the UFS device
Yaniv Gardi [Wed, 15 Jan 2014 21:57:53 +0000 (23:57 +0200)]
scsi: ufs: disable LCC configuration in the UFS device

LCC configuration that is needed for optical connections, is not needed
when working with UFS devices. As this values is already disabled
in the host, it should also be disabled in the device.

Change-Id: I81a6ac7310ff9dbf2d6c571431e62beab107fdf2
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs-msm: enable UFSHCD_BROKEN_LCC
Subhash Jadavani [Fri, 10 Jan 2014 22:12:48 +0000 (14:12 -0800)]
scsi: ufs-msm: enable UFSHCD_BROKEN_LCC

LCC (Line Control Command) are being used for communication between
UFS host and UFS device. But UFS host controller on our MSM have the issue
with issuing the LCC commands to UFS device and hence disable LCC from
host side.

Change-Id: I155b6a4a1adb77c40c5b5e642b3a034ee24659f3
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: provide the quirk to disable the LCC
Subhash Jadavani [Fri, 10 Jan 2014 22:07:26 +0000 (14:07 -0800)]
scsi: ufs: provide the quirk to disable the LCC

LCC (Line Control Command) are being used for communication between
UFS host and UFS device. But some hosts might have the issue with
issuing the LCC commands to UFS device and in this case LCC could be
explicitly disabled from the host side.

Change-Id: I7b4d4a46d8d4e70bde088a5652decc7ba86a5617
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: don't enable interrupt aggregation
Subhash Jadavani [Fri, 10 Jan 2014 19:14:16 +0000 (11:14 -0800)]
scsi: ufs-msm: don't enable interrupt aggregation

Current versions of UFS host controllers on our MSMs have interrupt
aggregation logic broken. Interrupt aggregation may not work if both
threshold count and timeout is enabled. Hence disable interrupt
aggregation by enabling UFSHCD_QUIRK_BROKEN_INTR_AGGR quirk until
its fixed in the newer UFS host controller revisions.

Change-Id: I063c6d577c370bfcf5648b4b0df9292c30984c63
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: read ref clk and icc level during init only
Noag [Wed, 15 Jan 2014 08:52:53 +0000 (10:52 +0200)]
scsi: ufs: read ref clk and icc level during init only

In order to minimize resume latency, pre-fetch
icc levels and reference clock during initialization
and avoid reading them each link startup
during resume.

Change-Id: Iab705068e46114eb3caa00c6e1b88a7862385d08
Signed-off-by: Noag <noag@codeaurora.org>
[subhashj@codeaurora.org: resolved merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: Add hba->vops->clk_scale_notify()
Sahitya Tummala [Mon, 13 Jan 2014 09:54:18 +0000 (15:24 +0530)]
scsi: ufs-msm: Add hba->vops->clk_scale_notify()

Add hba->vops->clk_scale_notify() to get notified about clock
scaling and thus to configure phy timers and to update the
bus bandwidth vote accordingly.

Change-Id: I2f0cae8e787d0b4e764dc210db035add880428ce
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
8 years agoscsi: ufs: Add support for clock scaling using devfreq framework
Sahitya Tummala [Thu, 2 Jan 2014 07:57:14 +0000 (13:27 +0530)]
scsi: ufs: Add support for clock scaling using devfreq framework

The clocks for UFS device will be managed by generic DVFS (Dynamic
Voltage and Frequency Scaling) framework within kernel. This devfreq
framework works with different governors to scale the clocks. By default,
UFS devices uses simple_ondemand governor which scales the clocks up if
the load is more than upthreshold and scales down if the load is less than
downthreshold.

Change-Id: I1c3944a5b1771b967c1df3e441a75fd584d6e2a5
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
[gbroner@codeaurora.org: fix usage of devfreq governor data]
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[subhashj@codeaurora.org: resolved merge conflicts, dropped most of the
changes as they are already present on baseline]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: add queue fullness statistics
Dolev Raviv [Sun, 12 Jan 2014 11:51:23 +0000 (13:51 +0200)]
scsi: ufs: add queue fullness statistics

Add more statistics to allow tracking of tags occupancy
upon sending a new request. The statistics is kept separately
for 4 types of requests: read, write, urgent and flush.
All will consist only of data requests (eg. read, write, urgent).
This statistic is an enhancement of current tag statistic and
uses same infrastructure.

Change-Id: If5cea4aec4e94081d568a3661584b31665becfc6
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: fix a wrong condition when checking array size
Yaniv Gardi [Thu, 9 Jan 2014 11:18:55 +0000 (13:18 +0200)]
scsi: ufs-msm: fix a wrong condition when checking array size

This change fixes a wrong condition that results a false error message

Change-Id: Iacb9224eaa908c0eec612fe3570b38ada3f90b37
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: fix crash upon reading host_regs debugfs entry
Raviv Shvili [Thu, 9 Jan 2014 08:22:16 +0000 (10:22 +0200)]
scsi: ufs: fix crash upon reading host_regs debugfs entry

While reading host_regs debugfs entry, UFS controller
might be in low power mode. While in UFS runtime suspend mode the host
controller is being unclocked.
Reading the unclocked host controller registers, may cause a system crash.
In order to avoid that, UFS runtime suspend should be
held and released when done.

CRs-fixed: 594618
Change-Id: I4b850806352b59192340bc5b0bb480b4dd6553f1
Signed-off-by: Raviv Shvili <rshvili@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: enable workarounds for APQ8084 v1.1
Subhash Jadavani [Fri, 3 Jan 2014 19:08:35 +0000 (11:08 -0800)]
scsi: ufs-msm: enable workarounds for APQ8084 v1.1

Some of the workarounds (like skipping the suspend and giving 1ms delay
before every UIC DME commands) are still needed to enable the booting
from UFS device on APQ8084 v1.1 as well. This patch enables those
workarounds.

Change-Id: I6023403130e3ff87f918e1ab7eaf5a145935bfab
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: remove redundant "Illegal ufs-IOCTL" log for BLKROSET command
Noag [Mon, 30 Dec 2013 08:58:58 +0000 (10:58 +0200)]
scsi: ufs: remove redundant "Illegal ufs-IOCTL" log for BLKROSET command

This patch prevents the "ufshcd_ioctl: Illegal ufs-IOCTL cmd 4701" log
message from being printed during boot time.
4701(BLKROSET) is not supported but not an Illegal command to UFS.

CRs-fixed: 580449

Change-Id: I20d54b23c09bd8b72b671b979103424e2050e15f
Signed-off-by: Noa Rubens <noag@codeaurora.org>
8 years agoscsi: ufs-msm: Enable clock gating
Sahitya Tummala [Tue, 17 Dec 2013 06:17:32 +0000 (11:47 +0530)]
scsi: ufs-msm: Enable clock gating

Enable relevant PHY clocks to be turned off as part of ufshcd
clock gating. Also, enable clock gating by setting necessary
capabilities.

The clock gating delay is currently set to 150ms by default. It can
be changed if required via sysfs -
echo xx > /sys/bus/platform/devices/msm_ufs.1/clkgate_delay_ms

Change-Id: I41c0b4c560711540cc0630e752d7843fca3fb26c
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
8 years agoscsi: ufs: Add support for clock gating
Sahitya Tummala [Tue, 17 Dec 2013 06:16:13 +0000 (11:46 +0530)]
scsi: ufs: Add support for clock gating

The UFS controller clocks can be gated after certain period of
inactivity, which is typically less than runtime suspend timeout.
In addition to clocks the link will also be put into Hibern8 mode
to save more power.

The clock gating can be turned on by enabling the capability
UFSHCD_CAP_CLK_GATING. To enable entering into Hibern8 mode as part of
clock gating, set the capability UFSHCD_CAP_HIBERN8_WITH_CLK_GATING.

The tracing events for clock gating can be enabled through debugfs as:
echo 1 > /sys/kernel/debug/tracing/events/ufs/ufshcd_clk_gating/enable
cat /sys/kernel/debug/tracing/trace_pipe

Change-Id: I3e5e7e78130941ad7109fc05a46d7c3720245a1a
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
[gbroner@codeaurora.org: fix merge conflicts]
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[subhashj@codeaurora.org: resolved merge conflicts, dropped most of the
changes as they are already present on baseline]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: Fix hba variant host op init and setup_clocks
Sahitya Tummala [Wed, 18 Dec 2013 08:19:27 +0000 (13:49 +0530)]
scsi: ufs-msm: Fix hba variant host op init and setup_clocks

Handle the case where vops->setup_clocks is called before vops->init()
from ufshcd driver.

Change-Id: I4754b658c1f37db6418560321f5dfe7a4650692b
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
8 years agoscsi: ufs: save and print current power info in the driver
Yaniv Gardi [Sun, 22 Dec 2013 19:07:09 +0000 (21:07 +0200)]
scsi: ufs: save and print current power info in the driver

There is no way to know the current working power info of the
driver, so in this patch, we save the power parameters, and we
print them to console.
This printing is necessary, since in case of crash, we can use those
logs to debug and investigate.

Change-Id: If0dc7a695c9b14a369e033e4c31787dcc2254ac3
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
[subhashj@codeaurora.org: resolved merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: add clock frequency table for Rate B
Yaniv Gardi [Thu, 26 Dec 2013 08:57:31 +0000 (10:57 +0200)]
scsi: ufs-msm: add clock frequency table for Rate B

The UFS driver is now supporting working in HS (High Speed), Rate B.
Hence, we need to add a static table of clock frequency for rate B gears.

Also, this change fixes array access to index -1, in certain corner
cases, and report illegal values that are returned from
msm_ufs_cfg_timers() routine

Change-Id: Id05321c4fd3ebcc509c6b53f3722c3acfb48cad3
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
[subhashj@codeaurora.org: fixed compilation errors]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: enable quirk for broken mode of TX 2 lanes
Yaniv Gardi [Wed, 25 Dec 2013 09:57:28 +0000 (11:57 +0200)]
scsi: ufs-msm: enable quirk for broken mode of TX 2 lanes

The default working mode should be TX 2 lanes, but
as this mode is not stable on the current controller, this quirk is
required so the unique mode will be TX 1 lane.

Change-Id: Iac8ed83207d66b8bd6a50cf1983f89df85525904
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: add a quirk for broken mode of TX 2 lanes
Yaniv Gardi [Wed, 25 Dec 2013 09:51:59 +0000 (11:51 +0200)]
scsi: ufs: add a quirk for broken mode of TX 2 lanes

The default working mode should be TX 2 lanes, but
as this mode is not stable on the current controller, this quirk is
required so the unique mode will be TX 1 lane.

Change-Id: Id2dc9e2a1b481007a894f0828d15d8f8ad61215c
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: change default working mode to rate B
Yaniv Gardi [Sun, 8 Dec 2013 13:56:38 +0000 (15:56 +0200)]
scsi: ufs-msm: change default working mode to rate B

Working throughput in UFS is affected by Gear, Number of lanes, and Mode
(PWM: Slow / SlowAuto,
 or
 HS: Fast /FastAuto).
When working in HS, throughput is affected by additional parameter -
Rate (A / B).
Here, we change the default working rate in HS to Rate B.

Change-Id: I35f63d5fc90ad1be19d886dda0bdcd4e54fe9c4c
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs-msm: switch off PHY PLL power rail during hibern8
Subhash Jadavani [Fri, 4 Oct 2013 10:53:14 +0000 (16:23 +0530)]
scsi: ufs-msm: switch off PHY PLL power rail during hibern8

If UniPro link is in Hibern8 state, low noise analog power rail for PLL
can be switched off along with main PHY analog power.

Change-Id: I20b113e5f004c824c330f72dc7649dac961bfe3e
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
8 years agoscsi: ufs: Override auto suspend tunables for ufs
Sujit Reddy Thumma [Fri, 6 Dec 2013 14:35:55 +0000 (20:05 +0530)]
scsi: ufs: Override auto suspend tunables for ufs

Override auto suspend tunables for UFS device LUNs during
initialization so as to efficiently manage background operations
and the power consumption.

Change-Id: Id7ff9e8a5c83b7503a329e71936af3234a22895b
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
[gbroner@codeaurora.org: fix minor merge conflicts]
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
8 years agoscsi: ufs-msm: phy configuration to support rate B
Yaniv Gardi [Sun, 8 Dec 2013 14:37:56 +0000 (16:37 +0200)]
scsi: ufs-msm: phy configuration to support rate B

This change adds phy configuration to support working in rate B
in case vendor power-mode preferences are pre-defined to work in
rate B.
Note: This change doesn't configure the default working rate
to be rate B, but only adds the support to do so.

Change-Id: Iec896917f9c76dcc3b5383c211871c7edf215b44
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: dump device descriptor info via debugfs
Yaniv Gardi [Sun, 8 Dec 2013 11:58:56 +0000 (13:58 +0200)]
scsi: ufs: dump device descriptor info via debugfs

This change adds a debugfs capability to dump Device Descriptor
information, parsed and detailed. It helps developer to get
important information about the UFS device it handles.

Change-Id: Ia149e4c82e33755b235eb6afe52541c8b23a0708
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: update device descriptor maximum size
Yaniv Gardi [Fri, 6 Dec 2013 01:37:25 +0000 (03:37 +0200)]
scsi: ufs: update device descriptor maximum size

According to JESD220B - UFS v2.0, the maximum size of device descriptor
has changed from 0x1F to 0x40. This patch updates the maximum size of
this descriptor.

Change-Id: I5f5de516a2d86e1f4409e44e1b2db62a624207b9
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs-msm: avoid powering off the device during system suspend
Sujit Reddy Thumma [Tue, 26 Nov 2013 06:58:31 +0000 (12:28 +0530)]
scsi: ufs-msm: avoid powering off the device during system suspend

Powering off the device during system suspend cause regressions
and device may go bad. This is mainly because of specification
violation of not holding RST_n line LOW during power up. Since
RST_n line cannot be controlled from software, avoid powering off
the device in first place.

Change-Id: I5cdb3b3b1685222d69717f079dc9fc43c97b01bf
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
8 years agoscsi: ufs: fix NULL pointer dereference when aborting command
Sujit Reddy Thumma [Fri, 22 Nov 2013 04:09:34 +0000 (09:39 +0530)]
scsi: ufs: fix NULL pointer dereference when aborting command

If there is a race between command completion and the scsi timeout,
the scsi timeout ignores the command completion and proceed with
aborting the command. Since the command completion happen in
interrupt context, it would be prioritized and ufshcd might free
resources before abort initiated by scsi is completed. Hence, if the
abort routine refers to the command info saved in lrbp it would cause
NULL pointer dereference. Fix this by using the command info provided
by scsi layer in the ufshcd_abort() argument.

Change-Id: Ie915880b1c239ef9080cfb5cb74f19329b3a82d4
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
8 years agoscsi: ufs-msm: disable quirk that adds delay after power more change
Yaniv Gardi [Sun, 24 Nov 2013 18:45:24 +0000 (20:45 +0200)]
scsi: ufs-msm: disable quirk that adds delay after power more change

As new PHY configuration attributes changed and more delays added to
DME commands, we can now remove this quirk and remains same stability
as before.

Change-Id: I8f0d2c045ca2f68e58913f4e9a1ce41ef4d77878
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: add retries to dme_peer get and set attribute
Lee Susman [Sun, 24 Nov 2013 13:39:01 +0000 (15:39 +0200)]
scsi: ufs: add retries to dme_peer get and set attribute

The dme_peer get/set attribute commands are prone to errors, therefore
we add three retries for the UIC command sending.
Error code returned from ufshcd_send_uic_cmd() is checked, and unless
it was successful or the retries have finished, another command will be
sent.

Change-Id: I63727228079cde897b4ed22ce0e87a8ca4814871
Signed-off-by: Lee Susman <lsusman@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
8 years agoscsi: ufs-msm: Fix turning off tx/rx lane synchronization clocks
Sujit Reddy Thumma [Wed, 20 Nov 2013 14:41:40 +0000 (20:11 +0530)]
scsi: ufs-msm: Fix turning off tx/rx lane synchronization clocks

The UFS PHY outputs tx/rx lane synchronization clocks which are
input to host controller via branch gating logic in GCC. These
clocks are enabled only when the PHY is powered on and Tx/Rx bursts
are active. Gating these clocks at runtime might lead to insufficient
clocks for the controller to close the tx/rx bursts. This further
lead to data transfer getting stuck after clocks are ungated.

Fix this by controlling the explicit enable/disable of these clocks
only when PHY state is changed. There will be no power impact of
leaving the clocks enabled at runtime because PHY dynamically manages
the gating and the clocks are really enabled only when tx/rx bursts
are active.

CRs-Fixed: 576719
Change-Id: Ib74bff641063eab36c7fd3e5fb7829c46a11aee0
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
[gbroner@codeaurora.org: fix merge conflicts - apq8084.dtsi file
location has been previously changed and is already up to date]
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
8 years agoscsi: ufs: add wrapper for retrying sending query attribute
Yaniv Gardi [Wed, 20 Nov 2013 20:55:45 +0000 (22:55 +0200)]
scsi: ufs: add wrapper for retrying sending query attribute

Sometimes queries from the device might return a failure so it is
recommended to retry sending the query, before giving up.
This change adds a wrapper to retry sending a query attribute,
in cases where we need to wait longer, before we continue,
or before reporting a failure.

Change-Id: I350a818f6a11c4f32310ca19c4c6f664381ba88d
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: fix debugfs tag stats resetting
Lee Susman [Tue, 19 Nov 2013 08:49:56 +0000 (10:49 +0200)]
scsi: ufs: fix debugfs tag stats resetting

When attempting to clear ufs tag stats, memset 0 is called with size
of multiples of unsigned int.
This is wrong since each cell in the stats array is of type (u64).
Fix the memset to sizeof(*tag_stats).

Change-Id: Iaeb70616a2160ee9cba4605e7251dc45868d1951
Signed-off-by: Lee Susman <lsusman@codeaurora.org>
8 years agoscsi: ufs-msm: remove command queue quirk
Yaniv Gardi [Sun, 17 Nov 2013 14:24:24 +0000 (16:24 +0200)]
scsi: ufs-msm: remove command queue quirk

So far the command queue for the whole UFS device was depend on the
UFSHCD_QUIRK_BROKEN_DEVICE_Q_CMND quirk due to stability issues.
Now, that we gained stability, with new UFS devices FW, we can
remove the UFSHCD_QUIRK_BROKEN_DEVICE_Q_CMND quirk

Change-Id: I7aef145e226e5b207d0146f58b5cd9c87ed5bb91
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: handle errors from PHY_ADAPTER_ERROR register
Dolev Raviv [Sun, 17 Nov 2013 11:12:13 +0000 (13:12 +0200)]
scsi: ufs: handle errors from PHY_ADAPTER_ERROR register

The PHY_ADAPTER_ERROR status register indicates PHY lane errors
reported by the M-PHY layer. In some occasions the controller
can recover from such errors. When the error is not recoverable,
a stuck DB error will occur. Since the stuck DB error is spotted
separately, no action other than clearing the register is necessary.

Change-Id: I4b9e8ab15018fe74da34264eac71f8110e94928a
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
8 years agoscsi: ufs: Add new file ufs-msm.h
Raviv Shvili [Wed, 13 Nov 2013 13:11:42 +0000 (15:11 +0200)]
scsi: ufs: Add new file ufs-msm.h

At the current implementation all the enums structs and defintions
defined at the ufs-msm.c. In order to share those definitions with
other files, we expose them at ufs-msm.h

Change-Id: I12fe3b9a51c86b5bf6584c2de65de40749ef5693
Signed-off-by: Raviv Shvili <rshvili@codeaurora.org>
8 years agoscsi: ufs-msm: change the vendor preferable power mode
Yaniv Gardi [Tue, 12 Nov 2013 18:21:18 +0000 (20:21 +0200)]
scsi: ufs-msm: change the vendor preferable power mode

As working with new UFS devices, and new version of FW,
we were able to work in a higher gear, and to maintain stability.
In this change the preferable values of the vendor power modes are
set to be HS-G2.
Also, a few minor indentation fixes are added.

Change-Id: I34d4836894b9d48085bbe2aa31a6f2d92661fb3d
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: add trace support for ufs power management
Sujit Reddy Thumma [Tue, 12 Nov 2013 16:48:08 +0000 (22:18 +0530)]
scsi: ufs: add trace support for ufs power management

Add ftrace support for profiling ufs power management latencies.
Usage:
echo 1 > /sys/kernel/debug/tracing/events/ufs/enable
cat /sys/kernel/debug/tracing/trace_pipe

Change-Id: If5c063179cc69a500d4902eb00b4ca3dc16e27f0
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: print scsi interpretation for aborted task
Dolev Raviv [Sat, 9 Nov 2013 18:12:08 +0000 (20:12 +0200)]
scsi: ufs: print scsi interpretation for aborted task

Adds the scsi interpretation of the aborted command,
in addition to the transfer dump. This change improves
crashes debugging.

Change-Id: I1b983042d90b8d0434260bb78e09807dd933a03a
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
8 years agoscsi: ufs: fix a bug in a UTRD info dump
Yaniv Gardi [Fri, 8 Nov 2013 17:34:20 +0000 (19:34 +0200)]
scsi: ufs: fix a bug in a UTRD info dump

The bug was a wrong parameter passed to print_hex_dump() function.

Change-Id: I962e08b8c1c8c546f0bc625da3bff292965da8a5
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs-msm: Add bus bandwidth voting support
Sujit Reddy Thumma [Fri, 11 Oct 2013 20:49:45 +0000 (13:49 -0700)]
scsi: ufs-msm: Add bus bandwidth voting support

The UFS host controller on MSM chipsets transfer data over
System NoC to the DDR memory. Add bus bandwidth voting support
based on the speed modes the host communicates with the device
so as to provide optimum throughput while transferring data over
the bus.

Change-Id: I1b407975984985fa108aa9373e2eab08b9027df4
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
[gbroner@codeaurora.org: fix merge conflicts - apq8084.dtsi file
location has been previously changed and is already up to date]
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts and also fixed
compilation error]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: add support for rx and tx to work in different num of lanes
Yaniv Gardi [Mon, 4 Nov 2013 09:01:41 +0000 (11:01 +0200)]
scsi: ufs-msm: add support for rx and tx to work in different num of lanes

Uni-pro lane management provides flexibility for tx/rx to work with
different number of lanes.
This change supports different number of lanes for TX and for RX.
The configured number of lanes for TX will be now the minimum between
the device capability and the vendor preferences.
Same logic applies when configuring RX number of lanes.

Change-Id: I9387a4489d910f89a0741c6349084051d7d94549
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: add index details to query error messages
Yaniv Gardi [Sun, 3 Nov 2013 12:20:20 +0000 (14:20 +0200)]
scsi: ufs: add index details to query error messages

When sending query to the device, the index  of the failure
is additional useful information that should be printed out as it
might specify the logical unit (LU) where the error occurred.

Change-Id: I15dd74545842bde7bbfb5bda56c20b5a28d54e75
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: phy configuration to support HS-G2
Yaniv Gardi [Wed, 30 Oct 2013 10:18:10 +0000 (12:18 +0200)]
scsi: ufs: phy configuration to support HS-G2

This change is required according to HW team, in order to support
UFS device working with HS-G2

Change-Id: Id76a36870103d93b9f602911412e999cce64cec1
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: read the device bRefClkFreq attribute
Yaniv Gardi [Wed, 30 Oct 2013 06:38:16 +0000 (08:38 +0200)]
scsi: ufs: read the device bRefClkFreq attribute

Device reference clock is a crucial parameter, as
it would fail to work in HS, if its value is different than 19.2 MHz.
This is why we should read its value upon start-up and notify
its value as a debug message.
We don't want to "blindly" configure this attribute as well, as this is
a one-time-programmable parameter and should be considered carefully
before setting it.

Change-Id: Ia2cc0f18fae1189949c30b5b2a65b763c1c46fb1
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: Inject errors to verify error handling
Sujit Reddy Thumma [Mon, 4 Mar 2013 17:45:13 +0000 (23:15 +0530)]
scsi: ufs: Inject errors to verify error handling

Use fault-injection framework to simulate error conditions
in the controller and verify error handling mechanisms
implemented in UFS host controller driver.

This is used only during development and hence
guarded by CONFIG_UFS_FAULT_INJECTION debug config option.

Change-Id: Ia63c276c5e56d677a92332b42b670300ad82af7a
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
8 years agoscsi: ufs: undo disabling LCC configuration in UFS device
Yaniv Gardi [Tue, 29 Oct 2013 10:32:16 +0000 (12:32 +0200)]
scsi: ufs: undo disabling LCC configuration in UFS device

So far we have disabled the LCC configuration in device and also in the
controller.
However, in some UFS devices, disabling the LCC configuration might fail
so we can remove this command. It was presented at first, just that the
controller and device will be configured identically (both with
TX_LCC_ENABLE disabled), but it shouldn't have any impact on the UFS
device behavior when removing this configuration command from the device.

Change-Id: I87342a63c75d28a91f0d1ab8edd819d13b3a21a1
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi :ufs: verify hba controller hce reg value
Raviv Shvili [Mon, 28 Oct 2013 12:58:29 +0000 (14:58 +0200)]
scsi :ufs: verify hba controller hce reg value

Sometimes due to hw issues it takes some time to the
host controller register to update. In order to verify the register
has updated, a polling is done until its value is set.

In addition the functions ufshcd_hba_stop() and
ufshcd_wait_for_register() was updated with an additional input
parameter, indicating the timeout between reads will
be done by sleeping or spinning the cpu.

Change-Id: Id79d92a4a0bc05d385eb47c027fe19a765f71851
Signed-off-by: Raviv Shvili <rshvili@codeaurora.org>
[subhashj@codeaurora.org: resolved merge conflicts, dropped the changes
in drivers/scsi/ufs/ufshcd-pci.c]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: add queries retry mechanism
Dolev Raviv [Mon, 28 Oct 2013 12:44:49 +0000 (14:44 +0200)]
scsi: ufs: add queries retry mechanism

Some of the queries might fail during init. To avoid
system failure, we add retry mechanism to issue queries
several times.

Change-Id: Ibab1d1dbfbaab763baad63c24218289b61da7b28
Signed-off-by: Raviv Shvili <rshvili@codeaurora.org>
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: enable the quirk to add delay before dme commands
Yaniv Gardi [Fri, 25 Oct 2013 07:12:47 +0000 (10:12 +0300)]
scsi: ufs: enable the quirk to add delay before dme commands

Before each dme command (get, set), delay is required for
stability purposes.
This change enables that quirk.

Change-Id: I8ef88f08562de444cb81e767c4d8aeb35b6bb0ea
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: add quirk for delay before dme commands
Yaniv Gardi [Fri, 25 Oct 2013 07:09:21 +0000 (10:09 +0300)]
scsi: ufs: add quirk for delay before dme commands

add delay before each dme command (get, set), as this delay is
required for stability purposes.

Change-Id: I5aca4c25f251c41c6764269366a8ca7235ffafc1
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
8 years agoscsi: ufs: disable LCC configuration
Yaniv Gardi [Thu, 24 Oct 2013 21:53:06 +0000 (00:53 +0300)]
scsi: ufs: disable LCC configuration

LCC configuration that is needed for optical connections, is not needed
when working with UFS devices. This values can be disable in all tx
connected lanes and in both: unipro and the device

Change-Id: I3c94600dad0aaade87eb976b6296a284d10aff93
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: fix spelling in variable
Dolev Raviv [Thu, 17 Oct 2013 07:50:06 +0000 (10:50 +0300)]
scsi: ufs: fix spelling in variable

A variable named ioct_data should have named ioctl_data. This change is
important for synchronizing the original change with mailing list version.

Change-Id: I224989d3caf2ee0faad6b99cd6774983438c5464
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: replace debugfs mutex with spinlock
Yaniv Gardi [Thu, 24 Oct 2013 08:26:33 +0000 (11:26 +0300)]
scsi: ufs: replace debugfs mutex with spinlock

Using a mutex is problematic if the code can run in interrupt context.
In this patch we replace the ufs debugfs synchronization mechanism
from mutex to spinlock, which doesn't go to sleep.

Change-Id: I4e258898ed0ddf5b84d955fabd4354c2d2891c3d
Signed-off-by: Lee Susman <lsusman@codeaurora.org>
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: Enable quirk to ignore sending WRITE_SAME command
Sujit Reddy Thumma [Wed, 16 Oct 2013 01:47:05 +0000 (18:47 -0700)]
scsi: ufs: Enable quirk to ignore sending WRITE_SAME command

WRITE_SAME command is not supported by UFS. Enable a quirk for
the upper level drivers to not send WRITE SAME command.

Change-Id: If3108134ceefbcb9c8585c1b489b4124ffa6b1ad
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: override HS rate series with vendor specifics
Sujit Reddy Thumma [Tue, 15 Oct 2013 17:56:31 +0000 (10:56 -0700)]
scsi: ufs-msm: override HS rate series with vendor specifics

High Speed rate series might always be set to rate "A" if the
vendor doesn't specify any rate during pre-power change notify.

Change-Id: Ied7ce3eba98ffbece97ec06eb6cab8df1d104f52
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
8 years agoscsi: ufs: add ioctl interface for query request
Dolev Raviv [Sun, 13 Oct 2013 06:26:35 +0000 (09:26 +0300)]
scsi: ufs: add ioctl interface for query request

This patch exposes the ioctl interface for UFS driver via SCSI device
ioctl interface. As of now UFS driver would provide the ioctl for query
interface to connected UFS device.

Change-Id: I7a5cea8de925dc0ecb6643774321e2c3690c504e
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
[gbroner@codeaurora.org: dropping changes to the following files:
 include/uapi/scsi/Kbuild
 include/uapi/scsi/ufs/Kbuild
 include/uapi/scsi/ufs/ioctl.h
 include/uapi/scsi/ufs/ufs.h
which are already included in previous change titled:
'uapi: scsi: ufs: add ioctl interface for query request']
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts and compilation
errors]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agouapi: scsi: ufs: add ioctl interface for query request
Dolev Raviv [Sun, 13 Oct 2013 06:26:35 +0000 (09:26 +0300)]
uapi: scsi: ufs: add ioctl interface for query request

This patch exposes the ioctl interface for UFS
driver via SCSI device ioctl interface. As of
now UFS driver would provide the ioctl for query
interface to connected UFS device.

Change-Id: Ib8301a69550408bfcb5fc85bb9c0498450c8cc31
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
Signed-off-by: Abhimanyu Kapur <abhimany@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: fix a compilation warning
Yaniv Gardi [Fri, 11 Oct 2013 02:15:16 +0000 (19:15 -0700)]
scsi: ufs: fix a compilation warning

Assign a value to 'ret' in order to prevent a compilation warning of:
'ret' may be used uninitialized in this function.

Change-Id: Id10d0e5e8204d233cf4906bc33709d3c012d964f
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: change the default preferences of vendor pwr change to HS
Yaniv Gardi [Thu, 10 Oct 2013 20:20:54 +0000 (13:20 -0700)]
scsi: ufs: change the default preferences of vendor pwr change to HS

In this change the default preferences of the UFS vendor
are set to work in HS-G1- 1 Lane, as the enviroment became stable.

Change-Id: I340190d5c6cf4f848f9def7eba8831fb299adadb
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs-msm: avoid code duplication when setting timer register
Yaniv Gardi [Wed, 9 Oct 2013 10:26:14 +0000 (03:26 -0700)]
scsi: ufs-msm: avoid code duplication when setting timer register

since two different routines implement almost the same logic of
scanning the ufs clocks, getting the rate of "core_clk" and
setting a vendor timer register with a calculated value,
we should use only one routine to do that in order to minimize
potential errors

Change-Id: I22728295074acfbe4d421996ea9eaa1f29cb3a32
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs-msm: add vendor specific support for power change callback
Yaniv Gardi [Wed, 9 Oct 2013 09:16:54 +0000 (02:16 -0700)]
scsi: ufs-msm: add vendor specific support for power change callback

Sometimes, the device shall report its maximum power and speed
capabilities, but we might not wish to configure it to use those
maximum capabilities.

In this change we implement the vendor specific callback that should
determines what parameters we should use in power change.
It takes into account the maximum capabilities of the device, and
also the pre-defined vendor preferences.
According to both set of parameters, it calculates the maximum power
and speed that are still acceptable by both: the vendor preferences
and the devices capabilities.

Change-Id: I3ef468d3882f3ed9d49a99aa285af4a1f58063a0
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
[subhashj@codeaurora.org: fixed compilation errors]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: fix fall-through in switch case
Yaniv Gardi [Tue, 8 Oct 2013 02:40:31 +0000 (19:40 -0700)]
scsi: ufs-msm: fix fall-through in switch case

fix fall through in msm_ufs_link_startup_notify() during PRE_CHANGE,
since we would like msm_ufs_enable_tx_lanes(hba) to happen only in
POST_CHANGE

Change-Id: I91b1134ef7060ee8b8189335d0ef7b5a4f546534
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs-msm: fix issue with setting the ref_clk enable flag
Sujit Reddy Thumma [Fri, 4 Oct 2013 04:58:12 +0000 (21:58 -0700)]
scsi: ufs-msm: fix issue with setting the ref_clk enable flag

Fix missing update of ref_clk enable reference count when the
clocks are enabled and also enable shutting down the phy and
device during system suspend.

Change-Id: I7772cd87e0d0528ab5dbe6ea9f09e6d02c86f96c
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
8 years agoscsi: ufs: expose driver run time data and hci regs via debugfs
Yaniv Gardi [Thu, 3 Oct 2013 21:12:21 +0000 (14:12 -0700)]
scsi: ufs: expose driver run time data and hci regs via debugfs

This change adds a few more options to a user to get a complete
status and statistics regarding the UFS driver, via debugfs
This information includes:
1. UFS Host Controller registers (cat /sys/kernel/debug/ufs/host_regs)
2. hba values (cat /sys/kernel/debug/ufs/show_hba)

Change-Id: Iac60de81a56ed42de72c3a7946a0d2bb5fab2903
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs: dump debug info during failures
Dolev Raviv [Thu, 3 Oct 2013 06:39:30 +0000 (09:39 +0300)]
scsi: ufs: dump debug info during failures

Inserts driver dumps for UFS Host Controller registers, Transfer Requests
and Task Management Requests.
The dumps will occur on driver initialization failure, ufshcd_abort() and
on error handling path.

Change-Id: Ie8683e22a619cdae20680b15930e546e84f8aa73
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: add power management support
Subhash Jadavani [Tue, 1 Oct 2013 07:41:35 +0000 (13:11 +0530)]
scsi: ufs-msm: add power management support

This patch adds the vendor specific UFS power management support for MSM
platform.

If UFS link hibernate operation is broken in HW, make sure that link
remains active and device in sleep state during the runtime suspend.
During system suspend, keep both link and device in power off state.

If UFS link hibernate operation is working properly in HW, keep the link
in hibernate state and device in sleep state during both runtime and
system suspend.

Change-Id: Ibc5be00eb9d5fd72ed116b887d835a12ed97ae78
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs: Allowing power mode change
Yaniv Gardi [Wed, 2 Oct 2013 17:02:02 +0000 (10:02 -0700)]
scsi: ufs: Allowing power mode change

Due to M-PHY issues, moving from HS to any other mode or gear or
even Hibern8 causes some un-predicted behavior of the device.
This patch fixes this issues.

Change-Id: I4540e30703aa1212099b2316e158b09e311c7420
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: enable broken power mode change quirk
Sujit Reddy Thumma [Wed, 2 Oct 2013 05:09:19 +0000 (22:09 -0700)]
scsi: ufs-msm: enable broken power mode change quirk

UFS devices on msm ufs v1.1 controller fail to change power mode
during initialization. Enable the UFSHCD_QUIRK_BROKEN_PWR_MODE_CHANGE
quirk to make sure the power mode is not switched.

Change-Id: Ie02ae5a2da3604a83828325719eb5edb167ca82e
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
8 years agoscsi: ufs-msm: enable broken command queuing quirk
Yaniv Gardi [Tue, 1 Oct 2013 10:57:29 +0000 (03:57 -0700)]
scsi: ufs-msm: enable broken command queuing quirk

Some devices, even though advertises command queuing capability,
may not behave well when multiple commands are queued concurrently.
Disable command queuing for the device to avoid command hangs when
multiple commands are sent.

Change-Id: I7458c081976e96d2a97c8c9544acfd29163d9e1f
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
8 years agoscsi: ufs-msm: Add reference clock control support
Sujit Reddy Thumma [Tue, 24 Sep 2013 03:43:00 +0000 (09:13 +0530)]
scsi: ufs-msm: Add reference clock control support

Reference clock is propogated from source to PHY with various
LDO gating logic in between. Add support for enabling these
LDOs and also source reference clock.

Change-Id: I0de6d5d47aff175cd5526b6de2f8e4078cb08316
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
8 years agoscsi: ufs: try read capacity (10) first
Sujit Reddy Thumma [Mon, 30 Sep 2013 23:17:52 +0000 (04:47 +0530)]
scsi: ufs: try read capacity (10) first

UFS 1.1 specification defines READ_CAPACTIY(16) as an optional
command. Hence, try READ_CAPACITY(10) first, if the device returns
0xFFFF_FFFF as returned logical block address then send
READ_CAPACITY(16) to read the actual device capacity.

Change-Id: I2690d26be967e6be4debdc773100c55ba751aa1f
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoscsi: ufs-msm: modify PHY register configurations
Sujit Reddy Thumma [Wed, 11 Sep 2013 04:52:29 +0000 (10:22 +0530)]
scsi: ufs-msm: modify PHY register configurations

Modify the PHY power up calibration values according to the
latest hardware specification.

Change-Id: I145dc8d5644c1914bb0fcb9c9b5790cf2b8de367
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
8 years agoscsi: ufs-msm: Enable 64-bit addressing support quirk
Sujit Reddy Thumma [Sat, 7 Sep 2013 15:52:01 +0000 (21:22 +0530)]
scsi: ufs-msm: Enable 64-bit addressing support quirk

MSM UFS host controller advertises CAP.64AS bit as zero
even though it can adress upto 36 bits.

Change-Id: Ia8edd9ede3cc5e8358775d1efca5451cc3559773
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
8 years agoscsi: ufs: Allow 64-bit broken quirk
Sujit Reddy Thumma [Sat, 7 Sep 2013 15:46:15 +0000 (21:16 +0530)]
scsi: ufs: Allow 64-bit broken quirk

Some UFS host controllers might advertise that 64-bit
addressing is not supported even though it supports >32-bit
addressing. Add a quirk so that 64-bit is enabled and dma mask
is set accordingly.

Change-Id: Ie17662f55dda1da7d508efb881ac8fb8fa95f15a
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
8 years agoufs-pltfrm: initialize DMA mask for device-tree probed device
Akinobu Mita [Mon, 19 Aug 2013 13:56:05 +0000 (22:56 +0900)]
ufs-pltfrm: initialize DMA mask for device-tree probed device

The device-tree probed device for ARM doesn't have dev->dma_mask.
So dma_set_mask() for the device doesn't succeed.  The popular trick
for this is - dev->dma_mask = &dev->coherent_dma_mask;

Currently there is no dma_set_mask() call in ufs-pltfrm, but the
forthcoming fix needs proper DMA mask setting in ufs core driver.  So
initializing dev->dma_mask as described above is required.

Change-Id: I8428f106ca2d97badb7bf57cbb1d3ee14dddaf7f
Signed-off-by: Akinobu Mita <mita@fixstars.com>
Cc: Sujit Reddy Thumma <sthumma@codeaurora.org>
Cc: Vinayak Holikatti <vinholikatti@gmail.com>
Cc: Santosh Y <santoshsy@gmail.com>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>
Cc: linux-scsi@vger.kernel.org
Patch-mainline: linux-scsi@vger.kernel.org @ 2013/08/19 19:26
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
8 years agoscsi: ufs-msm: Fix unnecessary poll during initialization
Sujit Reddy Thumma [Sat, 7 Sep 2013 14:55:54 +0000 (20:25 +0530)]
scsi: ufs-msm: Fix unnecessary poll during initialization

In msm_ufs_check_hibern8(), the loop never breaks until
timeout even if the tx_fsm_val is equal to expected value.

Change-Id: I6f5ee6aea2e50ff6c88547d5e651d6cccfd25212
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>