UFS flag query requests may fail sometimes due to timeouts etc.
Add a wrapper function to retry up to 10 times in case of such
failure, similar to retries being made for attribute queries.
Change-Id: Ie3ea4b3c516481e9ec176ab9db884a8a75cd33f9
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
The 3.14 kernel has changed the members of the bio data structure. This
change updates those data structures referenced in the ufs qcom ice
driver.
Change-Id: I60e982bce8f59b87c30e0f63999914ee5c401f0a
Signed-off-by: Krishna Konda <kkonda@codeaurora.org>
This change adds support for following changes in register interface for
newer UFS controllers:
The register UFS_ICE_CTRL_INFO_n_1 contains 32-bit LSB of crypto data-unit
base number. The register UFS_ICE_CTRL_INFO_n_2 contains 32-bit MSB of the
crypto data-unit base number. The register UFS_ICE_CTRL_INFO_n_3 contains
bitfields BYPASS, CNFG_KEY_INDX, and CDU_SIZE.
Change-Id: I2a9b0b87e912a876e46746431c75e32a0e21a1c6
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
Signed-off-by: Krishna Konda <kkonda@codeaurora.org>
Kernel coding style requires to use actual functions for
function-like or lengthy macros.
The statistics macros are such, so replace them with functions.
Change-Id: I464768ccb7ba5bba4149dc45adacd777c08a2413
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
A race condition appear to exist between request completion when
scsi_done() is called to end the request and set the tag back to
-1 (at blk_queue_end_tag() scsi_end_request), and scsi layer error
handling which aborts the command and reuses it to request sense
data. Sending the request sense is done with tag which was set to -1
and so it is invalid.
Assert command tag passed from scsi layer is valid.
Change-Id: I71b82e1e6aca4bbf316a2a732a42c564ab0d2248
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
debugfs entries that were set up on driver initialization
were not removed in the driver unloading path.
Added removal of the debugfs entries.
Also, cleaned up the unnecessary macro wrapping those functions.
Change-Id: I656b1f76713684547d1f9ca3aa75430b47bd5eff
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
vendor specific setup_clocks ops may depend on clocks managed by ufshcd
driver so if the vendor specific setup_clocks callback is called when
the required clocks are turned off, it results into unclocked register
access.
This change make sure that required clocks are enabled before vendor
specific setup_clocks callback is called.
Change-Id: I670c6b69aa361eb5023ef7d945ff45c3fa986fd7
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
Performing several writes to UFS host controller registers has
no gurrantee of ordering, so we must make sure register writes
to setup request list base address etc. are performed before the
run/stop register is enabled.
In addition, when setting up a task request, we must make sure
the updating of descriptors takes places before ringing the
doorbell, similarly to setting up a transfer request.
Change-Id: I740331fe94da3cf8a8e7faee9020c88889aadea3
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
Whenever some UFS failure occurs the driver prints the UFS
registers in order to help with analysis of the failure.
However this may not be sufficient in some cases, so having
the host controller state as it is represented and managed in
the driver will contribute to analysis efforts.
Added prints of various fields in the hba struct which may be
of interest.
Change-Id: I8385a6b40f6937f07d8f0f0c51f5cf36babf7515
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[subhashj@codeaurora.org: resolved merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
UFS lane symbol clocks can be disabled if the UFS link is not active,
this change adds support to vote these clocks off when link is inactive.
Change-Id: Id441d34b0b8ad4f3a3f3e0dacb8c9797b1de64b6
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
UFS power management features (clock gating & scaling, Hibern8 on Idle)
are kept disabled until they are verified on latest UFS host controller.
Now that they are verified on newer host controller, this change enables
them.
Change-Id: I9fb94ee58ab5fbbd5d22a0190624e1a8839060f0
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
On latest UFS PHY HW revisions, UFS host controller secure configuration
is retained even during UFS host controller power collapse so we can
skip restoring the secure configuration after coming out of power collapse.
Change-Id: I6cb882c99bd621622286c0f045cbefd9c1b1a0b7
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
UFS exposes a debug-fs directory with various information under
the name "ufs", which will not scale in case more than one UFS
controller is available in the system.
Add the instance number (inherited from the scsi host number) to
the debug-fs entry name.
Change-Id: I1a31be72b90c26cc840219d7ba2944ec4c0bc8f8
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[subhashj@codeaurora.org: resolved merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
When running benchmarks on a system and inspecting the effect of
performance related changes it can be useful to know in a
simple way how long it takes for UFS requests to complete.
Add statistics for UFS requests completion times and measure
minimum, maximum and average completion times for all requests
and also according to request type: read, write and flush.
Change-Id: I85639d629939e3ae3bba6de065ceadae0da3dc99
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[subhashj@codeaurora.org: resolved merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
rq_data_dir(rq) will always be either READ or WRITE so conditional
logic could never classify a request as a flush request causing
flush statistics to always be zero.
In addition it is neccesary to check the request type is FS in
order not to count other request type as read/write.
Change-Id: I678203ba47f8296caefa3f197566f2c65abdf059
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
Until now, the phy-qcom-ufs-*.* files used ufs data structures and
macros and thus, we had to expose most of them in include/linux/scsi/ufs
path. But now, after removing support for phy 28nm in apq8084 under
kernel 3.14, we can minimize the exposure of code to essential minimum.
To do that, we relocate the ufs.h, unipro.h, ufshcd.h and ufs-qcom.h
files back to reside internally in the driver.
Also this patch contains some very minor changes suggested by the
upstream checkpatch script.
Change-Id: Id2a923a6a0b1c76565c25f2797a666f3a0d1315f
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
[subhashj@codeaurora.org: resolved merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[venkatg@codeaurora.org: fixed header includes and other
trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
This is a snapshot of gdsc-regulator documentation as of
msm-3.18 commit:
e70ad0cd5efdd9dc91a77dcdac31d6132e1315c1 (Promotion of
kernel.lnx.3.18-151201.)
Signed-off-by: Devesh Jhunjhunwala <deveshj@codeaurora.org>
UFS Unit tests are used by test teams to test stability
and performance of the UFS driver.
They are inactive unless manually activated and do not impact the
functionality of the UFS driver.
Change-Id: I41ae523dce60b05bb57554f9f8f38c42dbdea4a7
Signed-off-by: Maya Erez <merez@codeaurora.org>
HS-G3 mode is working as expected with newer host controller revisions
hence this change removes the restriction of only running in PWM gears.
Change-Id: I4df0b6875455730e990a20a2810784f1c32d949f
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
The old names doesn't include the driver name (as prefix or at all).
This change adds the "ufs" and the "ufs-qcom" prefix to file names
and by that creates uniform naming convention in the driver.
Change-Id: I221b489cc4237882d7e62a9d80bc1ee3f2bcf4a6
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
Trace events have their own trace_<name>_enabled() function
that can be called in order to check if its enabled or not.
FTRACE_EVENT_ENABLED is redundant and will be dropped so
use the trace event function instead.
Change-Id: I4d2cc031ebbd5250bcff9526eaa916d6d691dbfc
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[subhashj@codeaurora.org: resolved merge conflicts]
Until now, the decision if phy calibration is according to rate A or
rate B values, was done in the phy driver. It made the phy dependent on
the ufs unipro which is unnecessary binding.
This change moves the decision into the ufs driver, and pass it through
a function parameter to the calibration routine in the phy driver.
Change-Id: I7a51d84142c31da57ba5de6ec98526e5c7d1b544
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
Previous code enables runtime pm before ufshcd_init() is completed,
and before the hba struct is stored in the platform device private
data. This means that pm runtime calls will have null hba pointer
as well as partially initialized driver.
Instead, enable pm runtime only after ufshcd_init() is done and
after hba struct is stored in the platform device private data.
Change-Id: I8225736916a9eda3d9f58d2b0e2566065766b914
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
QUniPro controller requires additional configuration before and after
clock scaling, this change adds the support for it.
Change-Id: I0add27ff3ab54f72b8b79e1e554541c2e492a4c8
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
Some UFS host controller implementation may require vendor specific
configurations before and after changing the UFS controller
clock frequencies. This change adds the support for this.
Change-Id: Id4171ef8786fa6883d9af914dc2a675cb62c6a72
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
Newer UFS controllers (revision 2) still need to be validated properly
hence disable the low power modes for it until they are validated
thoroughly.
Also run the UFS interface in PWM gear until High Speed Gear operation
is stabililized.
Change-Id: I310b49030d084557f487f3095fc7e1cfa68335e6
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
UFS device reference clock control has moved inside UFS controller register
address space for newer Qualcomm chipsets and if we try to do ioremp on the
corresponding memory address then it would fail as the same memory address
space is already ioremapped.
This issue is fixed by removing the requirement of passing reference clock
control register address space resource via device tree node for newer
chipsets.
Change-Id: I8d93f9856d33d3b300bd7994d1dff1d1be84596d
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[subhashj@codeaurora.org: resolved merge conflicts, skipped changes to
msmthulium.dtsi]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
Newer revisions of Qualcomm UFS host controller may not advertise
the correct version information in UFS HCI VER register. To handle
this, enable UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION to let UFS standard
host controller driver call into vendor specific operation to get
right UFS HCI VER register value.
Change-Id: Ibd50b8bb8a87003181ea306690e87728576d49fb
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
Some UFS devices send incorrect LineCfg data as part of power mode change
sequence which may cause host PHY to go into bad state. Currently we
workaround this issue by disabling the device's TX LCC but disabling TX
LCC is much more complicated if both host and device supports UniPro 1.6
specification. To simplify the workaround, this change disables the host
PHY's RX LineCfg to skip processing incorrect LineCfg from device.
Change-Id: I1eac56c11dd001eb0c53ba8e16aa512a656ab9ea
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
Change the maximum high speed gear to HS-G3 so if both host and device
supports HS-G3, UFS link will be allowed to operate in HS-G3.
Change-Id: I1117990948f9c09ae103cd1e692716e0010362cb
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
HS-G3 operations may not reliably work on legacy QCOM UFS host controller
hardware (major revision = 0x01) even though capability exchange during
link startup phase may end up negotiating maximum supported gear as G3.
This change downgrades the maximum supported gear to HS-G2 for legacy
host controllers.
Change-Id: Iad95ed4271f83db888940263ea6c6c804d56a422
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
UFS driver's load based clock scaling feature scales down the ufs related
clocks in order to allow low power modes of chipsets. UniPro 1.6 supports
maximum gear up to HS-G3 (High Speed Gear3) and some of the chipsets
low power modes may not be allowed in HS-G3 hence this change adds support
to scale gear between HS-G3 and HS-G2 based on same existing load based
clock scaling logic.
Change-Id: I25c70230a77321efd654af7c496c43936324ae40
Signed-off-by: Subhash Jadavani <subhashj@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>
UFS host controller hardware may allow the host controller
to be power collapsed when UFS link is hibern8 state, this
change allows the UFS host controller to be power collapsed
during hibern8.
Change-Id: I42f962484b9d6635be1139b1fc6447dd2ca2200c
Signed-off-by: Subhash Jadavani <subhashj@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>
As of HW major version 2, bit 'UFS_DEV_REF_CLK_EN' which is used to
gate/ungate the ref_clk to external UFS device, was moved into the
UFS register space to UFS_CFG1 register. This change adds support
to appropriately control the device reference clock and it also
adds the missing documentation for the device reference clock control
register address space.
Change-Id: I66a6a75dc5a1cf130b1cee90ae20f9f950edfb3a
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
It seems UFS version register (offset 08h) fields position has changed in
UFS HCI 2.0 specification when compared to 1.0/1.0 specification.
According to 2.0 spec, UFS version register value should be 0000_0200h
(version 2.0). This change fixes the expected version register value and
also added the error message if host controller advertises invalid
version.
Change-Id: I2dd399fd7e47ce99b60591f7eac75e7305758bde
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
Currently clock scaling is suspended only after the host and device
are put in low power mode but we should avoid clock scaling running
after UFS link is put in low power mode (hibern8). This change
suspends clock scaling before putting host/device in low power mode.
Change-Id: Iff9846cee1345a3c0c8b1aaee0b4ad567f37ea79
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
If device raises the exception event in the response to the commands
sent during the runtime/system PM callbacks, exception event handler
might run in parallel with PM callbacks and may see unclocked register
accesses. This change fixes this issue by not scheduling the exception
event handler while PM callbacks are running.
Change-Id: I8644f50366d5c87ba6a5048e48703b3723ab241b
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
Add support for exposing debug registers via debugfs. This
can be used for runtime debugging of failures/errors without
the need to add more prints to the console.
In order to avoid unnecessary code duplication, the function
for dumping registers to a file (in debugfs.c) has been
slightly modified and exposed as an external function.
Signed-off-by: Dov Levenglick <dovl@codeaurora.org>
Change-Id: I77f9f3a6d041f805a93d095446f3e8077977036f
Adds support for configuring and reading the test bus and debug
registers. The configuration is controlled by debugfs. Reading can
be triggered either by debugfs or by the kernel code.
Change-Id: I943e3c1b1e383a91a8abbb8dab9714434c56b6f5
Signed-off-by: Dov Levenglick <dovl@codeaurora.org>
[imaund@codeaurora.org: Resolved context conflicts]
Signed-off-by: Ian Maund <imaund@codeaurora.org>
Add ICE debug prints for debugging purposes. These prints
will be shown as part of dumping registers during error handling.
Enabling can be controlled by debugfs.
Change-Id: I7d070cc8df099e6c526997d39973a3e1c161091b
Signed-off-by: Dov Levenglick <dovl@codeaurora.org>
Provide a mechanism for the userspace to suppress specific
debug prints via debugfs. This is useful in order to avoid
cases where too much printing would cause watchdog timers
to expire.
Change-Id: I2500b7621b631e260d98595ed8cfe7d5a496dc10
Signed-off-by: Dov Levenglick <dovl@codeaurora.org>
On some device, in some cases, the initialization time is
uncharacteristically long. This is within the standard which states
in section 13.4.6.1.2 (Dynamic Capacity Procedural Flow):
"The device initialization may take a time longer than normal
initialization..."
Therefore, making the loop pending on fDeviceInit to clear
longer.
CRs-Fixed: 776748
Change-Id: Ida491467da63ac9630d3ecc9b8f5c3e9ac5187c2
Signed-off-by: Dov Levenglick <dovl@codeaurora.org>
When sending a query to the device returns with a timeout error,
we clear the corresponding bit in the DOORBELL register but
we don't clear the outstanding_request field as we should.
This patch fixes this bug.
Change-Id: Ia7e0aa29b0d822742654ba206a5837b9091fdb4a
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
As of HW major version 2, a new bit 'UFS_DEV_REF_CLK_EN' was added
to UFS_CFG1 register which needs to be set as part of hibernate
enter/exit sequences during suspend/resume.
Change-Id: I66a6a75dc5a1cf130b1cee90ae20f9f950edfb3a
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
[imaund@codeaurora.org: Resolved context conflicts and updated a
conditional in ufs_qcom_advertise_quirks to use the ufs_qcom_host
struct when querying major hw versions]
Signed-off-by: Ian Maund <imaund@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts,
drop changes to include/linux/phy/phy-qcom-ufs.h]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
Provides a mechanism for the userspace to suppress specific
debug prints via the debugfs. This is useful in order to avoid
cases where too much printing would cause watchdog timers to expire.
Change-Id: I1ab068cd616ddac767ec5f30ab130e3b1ac34e15
Signed-off-by: Dov Levenglick <dovl@codeaurora.org>
[imaund@codeaurora.org: Resolved context conflicts]
Signed-off-by: Ian Maund <imaund@codeaurora.org>
[subhashj@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
ice_init may need UFS clocks to be enabled in order to allow
enabling ICE as part of its initialization. To allow that,
ice_init should be done as part of UFS initialization sequence.
In such a case ice_reset is no longer needed to be called as part of
UFS initialization and should be moved to host reset scenarios.
Change-Id: Iaa851083a9f73045c7ca02d69dd65b3a00b85bff
Signed-off-by: Maya Erez <merez@codeaurora.org>
If we write REG_UFS_SYS1CLK_1US & REG_UFS_TX_SYMBOL_CLK_NS_US registers
multiple times (especially when UFS symbol clocks are not running) then
it might make the HW to go back to default value of these registers.
This change updates above registers only if there is a change in these
registers value.
Change-Id: I7c94c477e52b36b26a1624fa3ddfa75a49916d58
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[imaund@codeaurora.org: Resolved context conflicts]
Signed-off-by: Ian Maund <imaund@codeaurora.org>
phy_init() calls "init" phy_ops and UFS phy driver might need
to know the UFS controller revision in this "init" ops hence
save the controller revision before calling phy_init().
Change-Id: I3e9d780dfa3da603b372b1fc4465dfd5f7cfb31a
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
DME attributes read/write commands need GenSelectorIndex argument and
according to UFS host controller specification, it should specify the
targeted M-PHY data lane.
This is the valid range of GenSelectorIndex for M-PHY attributes:
0 to (2 * PA_MaxDataLanes - 1)
Example (Note: PA_MaxDataLanes is UniPro protocol constant set to 4):
---------------------------------------
MPHY Access target | GenSelectorIndex
---------------------------------------
TX Lane0 | 0
TX Lane1 | 1
RX Lane0 | 4
RX Lane1 | 5
---------------------------------------
This change make sure that correct GenSelectorIndex is passed for M-PHY
attributes
Change-Id: I38c14b5801ece7fce7a7970385756859618efd32
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>