Commit Graph

984068 Commits

Author SHA1 Message Date
David Brazdil
4a7da93bdb ANDROID: KVM: arm64: Read and check S2MPU_VERSION
Read S2MPU_VERSION during driver init and check it against list of
supported versions. The register fields are as follows:
  - MAJOR_ARCH_VER,
  - MINOR_ARCH_VER,
  - REV_ARCH_VER,
  - RTL_VER.
Their exact use is not documented. For now, we mask out RTL_VER and
expect a match on MAJOR_, MINOR_ and REV_ARCH_VER. This may be tweaked
in the future.

Test: builds, boots
Bug: 190463801
Signed-off-by: David Brazdil <dbrazdil@google.com>
Change-Id: I2fbd20ab78a992c8bdb3574a6d480012260c9ded
2021-11-04 13:38:16 +00:00
David Brazdil
4e91a00153 ANDROID: KVM: arm64: Parse S2MPU MMIO region
Start EL1 portion of the S2MPU driver with an init function which
probes the Device tree for nodes compatible with 'google,s2mpu'.
Parse and check the base, size and power domain ID.

Test: builds, boots
Bug: 190463801
Signed-off-by: David Brazdil <dbrazdil@google.com>
Change-Id: Ic8b421e20b40b4a9fc5fb268dece00a11e35e3eb
2021-11-04 13:38:16 +00:00
David Brazdil
b2de5483b7 ANDROID: KVM: arm64: Create empty S2MPU driver
Create a skeleton driver for the S2MPU - an EL1 portion called during
KVM init which will parse the DT and configure the kernel, and an EL2
portion which will program the S2MPUs later at runtime. The code is
behind CONFIG_KVM_S2MPU.

Test: builds, boots
Bug: 190463801
Signed-off-by: David Brazdil <dbrazdil@google.com>
Change-Id: Ic6a3460cad69fba673754cc1926a5bac88f1fa17
2021-11-04 13:38:15 +00:00
David Brazdil
ff91ee259c ANDROID: dt-bindings: iommu: Add Google S2MPU
Add DeviceTree bindings for Google S2MPU.

Test: n/a
Bug: 190463801
Signed-off-by: David Brazdil <dbrazdil@google.com>
Change-Id: I002b5df1cac73766179d73ed56fe4945e8e7c2e6
2021-11-04 13:38:15 +00:00
David Brazdil
cc1ad46fb2 ANDROID: KVM: arm64: Add 'host_stage2_adjust_mmio_range' to kvm_iommu_ops
Add a new kvm_iommu_ops hook to the lower-EL instruction/data abort
handler, which allows the IOMMU driver to restrict the region of device
memory that is about to be mapped in the host stage-2.

This can be used by the IOMMU driver to restrict access to the MMIO
registers of the IOMMU itself.

Test: builds, boots
Bug: 190463801
Signed-off-by: David Brazdil <dbrazdil@google.com>
Change-Id: I58f7b7a78795a3bfc4d77f7128e4fdc1110fde58
2021-11-04 13:38:15 +00:00
David Brazdil
25f81ec77b ANDROID: KVM: arm64: Add 'host_mmio_dabt_handler' to kvm_iommu_ops
Add a new kvm_iommu_ops hook which allows the IOMMU driver to handle
data aborts in unmapped device memory regions. If the abort is handled
by the driver, the global abort handler will not attempt to map in the
page.

For example, this enables the IOMMU driver to virtualize access to
the underlying IOMMU hardware, or to allow access to a subset of the
functionality, eg. performance counters.

Test: builds, boots
Bug: 190463801
Signed-off-by: David Brazdil <dbrazdil@google.com>
Change-Id: Ie2e38652f0568c27d30190fcc3879592872863ae
2021-11-04 13:37:53 +00:00
David Brazdil
3cd8b5b00b ANDROID: KVM: arm64: Add 'host_stage2_set_owner' to kvm_iommu_ops
Add a new hook to kvm_iommu_ops that is invoked whenever a range of
pages changes their owner in the host stage2. This is currently limited
to finalize_host_mappings, which changes the owner of EL2-mapped pages
from host to hyp.

The driver is expected to apply corresponding changes in the IOMMU it
controls, so that only the new owner can access the page range.

Test: builds, boots
Bug: 190463801
Signed-off-by: David Brazdil <dbrazdil@google.com>
Change-Id: Ic5ca01a56344cd0253bf7b71560f057ba0e54d6b
2021-11-04 13:18:30 +00:00
David Brazdil
d2efcdcb2b ANDROID: KVM: arm64: Add 'host_smc_handler' to kvm_iommu_ops
IOMMU drivers need to intercept power management SMCs between the host
and EL3. Add a hook to hyp's 'handle_host_smc'.

Test: builds, boots
Bug: 190463801
Signed-off-by: David Brazdil <dbrazdil@google.com>
Change-Id: Ief42370ac371f6b3b87a0d46c00acfffece47052
2021-11-04 13:18:30 +00:00
David Brazdil
79775d0225 ANDROID: KVM: arm64: Introduce IOMMU driver infrastructure
Bootstrap infrastructure for IOMMU drivers by introducing kvm_iommu_ops
struct in EL2 that is populated based on a iommu_driver parameter to
__pkvm_init hypercall and selected in EL1 early init.

An 'init' operation is called in __pkvm_init_finalise, giving the driver
an opportunity to initialize itself in EL2 and create any EL2 mappings
that it will need. 'init' is specifically called before
'finalize_host_mappings' so that:
  (a) pages mapped by the driver change owner to hyp,
  (b) ownership changes in 'finalize_host_mappings' get reflected in
      IOMMU mappings (added in a future patch).

Test: builds, boots
Bug: 190463801
Signed-off-by: David Brazdil <dbrazdil@google.com>
Change-Id: Icd496d193c0bbf811406c3a8d4b94610e2a03197
2021-11-04 13:18:30 +00:00
Woody Lin
fddf813941 ANDROID: debug_symbols: Add show_mem
Add show_mem symbol which will be used by the hard-lockup
debugging module to debug_symbols driver.

Bug: 199478662
Signed-off-by: Woody Lin <woodylin@google.com>
Change-Id: I479700e9f1428b4e1192881b4e3b67c9e43afbeb
2021-11-04 08:42:54 +00:00
Bart Van Assche
4295353099 ANDROID: scsi: ufs: Align the HPB calls with the upstream code
The Android UFS driver calls the HPB functions in a different way than
the upstream UFS driver. Align the Android UFS driver with the upstream
driver.

Bug: 204438323
Change-Id: Ia98f96c86768db8f995ba31cbac20e76e7201e2b
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2021-11-03 13:31:37 -07:00
Bart Van Assche
bdb2117c28 ANDROID: scsi: ufs: Re-enable runtime power management
Android commit e7d848c921 ("FROMLIST: scsi: ufs: Fix deadlock while
suspending ufs host") disabled runtime power management. Re-enable
runtime power management since runtime power management support has
been fixed after that commit was merged.

Bug: 204438323
Change-Id: I4d473262e90f242bc55eaa07b8a3bf7ab47c1a65
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2021-11-03 13:31:37 -07:00
Bart Van Assche
568dd97549 ANDROID: scsi: ufs: Remove the ufs_rpmb_wlun_template
The upstream commit edc0596cc0 ("scsi: ufs: core: Stop clearing UNIT
ATTENTIONS") removed the ufs_rpmb_wlun_template but its Android backport
not. Hence this patch that removes the ufs_rpmb_wlun_template.

Bug: 204438323
Change-Id: I86206399a9745e26ad5f84c2cac2179a37ba80e7
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2021-11-03 13:31:37 -07:00
Bart Van Assche
6e41c820f6 ANDROID: scsi: ufs: Remove a local variable from ufshcd_abort()
Bring the Android code in sync with the upstream code. This patch does
not change any functionality.

Bug: 204438323
Change-Id: I8fe9f9f3c7d39feb1e211a6b6dc00d6e638ef1b4
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2021-11-03 13:31:37 -07:00
Bart Van Assche
69d296ea60 ANDROID: scsi: ufs: Remove a blank line
There is no blank line in the upstream code above the luns_avail
declaration. Hence this patch.

Bug: 204438323
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I79927cc14cc011c87eb96ca8847f0bd6a046bb40
2021-11-03 13:31:37 -07:00
Adrian Hunter
23dd19247d UPSTREAM: scsi: ufs: core: Do not exit ufshcd_err_handler() unless operational or dead
Callers of ufshcd_err_handler() expect it to return in an operational
state. However, the code does not check the state before exiting.

Add a check for the state and perform retries until either success or the
maximum number of retries is reached.

Link: https://lore.kernel.org/r/20211002154550.128511-3-adrian.hunter@intel.com
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Change-Id: Ib3818dd4fd956837418218b37f39ee837438a2be
Bug: 204438323
(cherry picked from commit 87bf6a6bbe)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2021-11-03 13:31:37 -07:00
Adrian Hunter
ccba7d5b8e UPSTREAM: scsi: ufs: core: Do not exit ufshcd_reset_and_restore() unless operational or dead
Callers of ufshcd_reset_and_restore() expect it to return in an operational
state. However, the code only checks direct errors and so the ufshcd_state
may not be UFSHCD_STATE_OPERATIONAL due to error interrupts.

Fix by also checking ufshcd_state, still allowing non-fatal errors which
are left for the error handler to deal with.

Link: https://lore.kernel.org/r/20211002154550.128511-2-adrian.hunter@intel.com
Reviewed-by: Avri altman <avri.altman@wdc.com>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit 54a4045342)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: Ibfa8f43aaa256c96efbfcb8e185067beb655d603
2021-11-03 13:31:36 -07:00
Bean Huo
e2919fba76 UPSTREAM: scsi: ufs: core: Remove return statement in void function
Return statement is not useful at the end of "void" function.

Link: https://lore.kernel.org/r/20210929200640.828611-4-huobean@gmail.com
Signed-off-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit f44abcfc3f)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I33a7a6dfbecb50baf017185b30e97089bb266e71
2021-11-03 13:31:36 -07:00
Bean Huo
1da235a555 UPSTREAM: scsi: ufs: core: Fix ufshcd_probe_hba() prototype to match the definition
Since commit 568dd99596 ("scsi: ufs: Rename the second ufshcd_probe_hba()
argument"), the second ufshcd_probe_hba() argument has been changed to
init_dev_params.

Link: https://lore.kernel.org/r/20210929200640.828611-3-huobean@gmail.com
Fixes: 568dd99596 ("scsi: ufs: Rename the second ufshcd_probe_hba() argument")
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Change-Id: I04365efcd6f0e4154f280eb66bd01590100009ad
Bug: 204438323
(cherry picked from commit 68444d73d6)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2021-11-03 13:31:36 -07:00
Anders Roxell
558e6162fe UPSTREAM: scsi: ufs: core: SCSI_UFS_HWMON depends on HWMON=y
When building an allmodconfig kernel, the following build error shows up:

aarch64-linux-gnu-ld: drivers/scsi/ufs/ufs-hwmon.o: in function `ufs_hwmon_probe':
/kernel/next/drivers/scsi/ufs/ufs-hwmon.c:177: undefined reference to `hwmon_device_register_with_info'
/kernel/next/drivers/scsi/ufs/ufs-hwmon.c:177:(.text+0x510): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `hwmon_device_register_with_info'
aarch64-linux-gnu-ld: drivers/scsi/ufs/ufs-hwmon.o: in function `ufs_hwmon_remove':
/kernel/next/drivers/scsi/ufs/ufs-hwmon.c:195: undefined reference to `hwmon_device_unregister'
/kernel/next/drivers/scsi/ufs/ufs-hwmon.c:195:(.text+0x5c8): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `hwmon_device_unregister'
aarch64-linux-gnu-ld: drivers/scsi/ufs/ufs-hwmon.o: in function `ufs_hwmon_notify_event':
/kernel/next/drivers/scsi/ufs/ufs-hwmon.c:206: undefined reference to `hwmon_notify_event'
/kernel/next/drivers/scsi/ufs/ufs-hwmon.c:206:(.text+0x64c): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `hwmon_notify_event'
aarch64-linux-gnu-ld: /home/anders/src/kernel/next/drivers/scsi/ufs/ufs-hwmon.c:209: undefined reference to `hwmon_notify_event'
/kernel/next/drivers/scsi/ufs/ufs-hwmon.c:209:(.text+0x66c): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `hwmon_notify_event'

Since SCSI_UFS_HWMON can't be built as a module, SCSI_UFS_HWMON has to
depend on HWMON=y.

Link: https://lore.kernel.org/r/20210927084615.1938432-1-anders.roxell@linaro.org
Fixes: e88e2d3220 ("scsi: ufs: core: Probe for temperature notification support")
Also-reported-by: Randy Dunlap <rdunlap@infradead.org>
Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
Acked-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit 60c98a87fc)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I233fa50a3b5ba54b609c05b3b271276db6339afb
2021-11-03 13:31:36 -07:00
Krzysztof Kozlowski
61a867f350 UPSTREAM: scsi: ufs: exynos: Unify naming
Use "Samsung" and "Exynos", not the uppercase versions.

Link: https://lore.kernel.org/r/20210924132658.109814-2-krzysztof.kozlowski@canonical.com
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit ce580e47e8)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I8baf39fa0c17a5a3760836067e993a8fbbdf5398
2021-11-03 13:31:36 -07:00
Avri Altman
061f867509 UPSTREAM: scsi: ufs: core: Add temperature notification exception handling
The device may notify the host of an extreme temperature by using the
exception event mechanism. The exception can be raised when the device’s
Tcase temperature is either too high or too low.

It is essentially up to the platform to decide what further actions need to
be taken. leave a placeholder for a designated vop for that.

Link: https://lore.kernel.org/r/20210915060407.40-3-avri.altman@wdc.com
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit 322c4b29ee)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: Iaf049a274fb4be5c3bffd92fa2651ed50b16ca29
2021-11-03 13:31:36 -07:00
Avri Altman
bbce73fc60 UPSTREAM: scsi: ufs: core: Probe for temperature notification support
Probe the dExtendedUFSFeaturesSupport register for the device's temperature
notification support and, if supported, add a hardware monitor device.

Link: https://lore.kernel.org/r/20210915060407.40-2-avri.altman@wdc.com
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit e88e2d3220)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I40639256cf1d2e70d5e80b09b03def001a9a5487
2021-11-03 13:31:36 -07:00
Bart Van Assche
de5b19ec47 UPSTREAM: scsi: ufs: core: Unbreak the reset handler
A command tag is passed as the second argument of the
__ufshcd_transfer_req_compl() call in ufshcd_eh_device_reset_handler()
instead of a bitmask. Fix this by passing a bitmask as argument instead of
a command tag.

Link: https://lore.kernel.org/r/20210916175408.2260084-1-bvanassche@acm.org
Fixes: a45f937110 ("scsi: ufs: Optimize host lock on transfer requests send/compl paths")
Cc: Can Guo <cang@codeaurora.org>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Change-Id: I53bedb5d1a253bf8b93a8beb19ac37c8a5321425
Bug: 204438323
(cherry picked from commit d04a968c33)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2021-11-03 13:31:35 -07:00
Peter Wang
abe3f3623b UPSTREAM: scsi: ufs: ufs-mediatek: Change dbg select by check IP version
Mediatek UFS dbg select setting is changed in new IP version.  Check the IP
version before setting dbg select.

Link: https://lore.kernel.org/r/1630918387-8333-1-git-send-email-peter.wang@mediatek.com
Signed-off-by: Peter Wang <peter.wang@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit aba3b0757b)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: Icda3c3bbaedd3d3e1d9ed84ee069b3867e89a93f
2021-11-03 13:31:35 -07:00
ChanWoo Lee
b580032ddc UPSTREAM: scsi: ufs: ufs-qcom: Remove unneeded variable 'err'
'err' is never set in this functon. Remove the declaration and just return
0.

Link: https://lore.kernel.org/r/20210907044111.29632-1-cw9316.lee@samsung.com
Signed-off-by: ChanWoo Lee <cw9316.lee@samsung.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit c4adf171e8)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I1c2febf84a1130c8230923b27379ca6f18f8afb2
2021-11-03 13:31:35 -07:00
Adrian Hunter
4348fcb2a8 UPSTREAM: scsi: ufs: ufs-pci: Fix Intel LKF link stability
Intel LKF can experience link errors. Make fixes to increase link
stability, especially when switching to high speed modes.

Link: https://lore.kernel.org/r/20210831145317.26306-1-adrian.hunter@intel.com
Fixes: b2c57925df ("scsi: ufs: ufs-pci: Add support for Intel LKF")
Cc: stable@vger.kernel.org
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit 1cbc9ad3ee)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I9df0fde35fd0c91abb182df3a4caa9922d679ca5
2021-11-03 13:31:35 -07:00
Martin K. Petersen
14684fc39d UPSTREAM: scsi: ufs: ufshpb: Use scsi_cmd_to_rq() instead of scsi_cmnd.request
Prepare for removal of the request pointer by using scsi_cmd_to_rq()
instead. This patch does not change any functionality.

Link: https://lore.kernel.org/r/20210809230355.8186-1-bvanassche@acm.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit 12bc2f13f3)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I40ce6f340cebc1d69af596b32b707b9bd4925248
2021-11-03 13:31:35 -07:00
Bart Van Assche
5ee37d89d5 UPSTREAM: scsi: ufs: Use scsi_cmd_to_rq() instead of scsi_cmnd.request
Prepare for removal of the request pointer by using scsi_cmd_to_rq()
instead. This patch does not change any functionality.

Link: https://lore.kernel.org/r/20210809230355.8186-48-bvanassche@acm.org
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit 3f2c1002e0)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: Ia097ab3da630dcadd70fb8efbfd212e60cfcc79c
2021-11-03 13:31:35 -07:00
Bart Van Assche
435df62d65 UPSTREAM: scsi: core: Introduce the scsi_cmd_to_rq() function
The 'request' member of struct scsi_cmnd is superfluous. The struct request
and struct scsi_cmnd data structures are adjacent and hence the request
pointer can be derived easily from a scsi_cmnd pointer. Introduce a helper
function that performs that conversion in a type-safe way. This patch is
the first step towards removing the request member from struct
scsi_cmnd. Making that change has the following advantages:

 - This is a performance optimization since adding an offset to a pointer
   takes less time than dereferencing a pointer.

 - struct scsi_cmnd becomes smaller.

Link: https://lore.kernel.org/r/20210809230355.8186-2-bvanassche@acm.org
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit 51f3a47889)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: Iba5551cbb5d80daaab10dbbdb302aac7892ea442
2021-11-03 13:31:35 -07:00
Colin Ian King
7da289ada7 UPSTREAM: scsi: ufs: ufshpb: Remove redundant initialization of variable 'lba'
The variable 'lba' is being initialized with a value that is never read, it
is being updated later on. The assignment is redundant and can be removed.

Link: https://lore.kernel.org/r/20210804133241.113509-1-colin.king@canonical.com
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Addresses-Coverity: ("Unused value")
Bug: 204438323
(cherry picked from commit 102851fc9a)
Change-Id: Ib32be0785fe1dba67f356587334d02843a7c2e0a
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2021-11-03 13:31:34 -07:00
Adrian Hunter
c1871d31d6 UPSTREAM: scsi: ufshcd: Fix device links when BOOT WLUN fails to probe
Managed device links are deleted by device_del(). However it is possible to
add a device link to a consumer before device_add(), and then discovering
an error prevents the device from being used. In that case normally
references to the device would be dropped and the device would be deleted.
However the device link holds a reference to the device, so the device link
and device remain indefinitely (unless the supplier is deleted).

For UFSHCD, if a LUN fails to probe (e.g. absent BOOT WLUN), the device
will not have been registered but can still have a device link holding a
reference to the device. The unwanted device link will prevent runtime
suspend indefinitely.

Amend device link removal to accept removal of a link with an unregistered
consumer device (suggested by Rafael), and fix UFSHCD by explicitly
deleting the device link when SCSI destroys the SCSI device.

Link: https://lore.kernel.org/r/a1c9bac8-b560-b662-f0aa-58c7e000cbbd@intel.com
Fixes: b294ff3e34 ("scsi: ufs: core: Enable power management for wlun")
Reviewed-by: Rafael J. Wysocki <rafael@kernel.org>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit bf25967ac5)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I68f785335dfd4b762130552cdf492a6ae974bc38
2021-11-03 13:31:34 -07:00
Colin Ian King
3b010f51a0 UPSTREAM: scsi: ufs: Fix unsigned int compared with less than zero
Variable 'tag' is currently an unsigned int and is being compared to less
than zero, this check is always false. Fix this by making 'tag' an int.

Link: https://lore.kernel.org/r/20210806144301.19864-1-colin.king@canonical.com
Fixes: 4728ab4a8e ("scsi: ufs: Remove ufshcd_valid_tag()")
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Addresses-Coverity: ("Macro compares unsigned to 0")
Bug: 204438323
(cherry picked from commit a5402cdcc2)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I541fe4699e1de7c173a9ec2246eb585c8ba103e5
2021-11-03 13:31:34 -07:00
Bean Huo
a704494924 UPSTREAM: scsi: ufs: core: Add lu_enable sysfs node
We need to check whether HPB is enabled on a given LU from the userspace
tool. Add lu_enable sysfs node.

Link: https://lore.kernel.org/r/20210804182128.458356-3-huobean@gmail.com
Tested-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit f5efd4fe78)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I37faf8f52f180b2b6443cbeffeace3ec47f0a85f
2021-11-03 13:31:34 -07:00
Bean Huo
19d3641c3d UPSTREAM: scsi: ufs: core: Add L2P entry swap quirk for Micron UFS
For Micron UFS devices the L2P entry need to be byteswapped before sending
an HPB READ command to the UFS device. Add the quirk
UFS_DEVICE_QUIRK_SWAP_L2P_ENTRY_FOR_HPB_READ to address this.

Link: https://lore.kernel.org/r/20210804182128.458356-2-huobean@gmail.com
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit 63522bf3ac)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I4c33a8df083551e04de486adcf68e7e13fc20a17
2021-11-03 13:31:34 -07:00
Bean Huo
e0ff4e3d3c UPSTREAM: scsi: ufs: core: Remove redundant call in ufshcd_add_command_trace()
ufshcd_add_cmd_upiu_trace() will be called later anyway. Simplify code by
moving if-statement.

Link: https://lore.kernel.org/r/20210802180803.100033-1-huobean@gmail.com
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Bug: 204438323
(cherry picked from commit f0101af435)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I96120124b178429ee02b0c6e67d78bc8b4e046c3
2021-11-03 13:31:34 -07:00
Bart Van Assche
3f9a325f48 UPSTREAM: scsi: ufs: Add fault injection support
Make it easier to test the UFS error handler and abort handler.

Link: https://lore.kernel.org/r/20210722033439.26550-19-bvanassche@acm.org
Acked-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Change-Id: I85a409ee2ed8b0a4ccb5a3c896d69809337bfbe3
Bug: 204438323
(cherry picked from commit c11a1ae9b8)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2021-11-03 13:31:34 -07:00
Bart Van Assche
246c1ab904 UPSTREAM: scsi: ufs: Optimize SCSI command processing
Use a spinlock to protect hba->outstanding_reqs instead of using atomic
operations to update this member variable.

This patch is a performance improvement because it reduces the number of
atomic operations in the hot path (test_and_clear_bit()) and because it
reduces the lock contention on the SCSI host lock. On my test setup this
patch improves IOPS by about 1%.

Link: https://lore.kernel.org/r/20210722033439.26550-14-bvanassche@acm.org
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Stanley Chu <stanley.chu@mediatek.com>
Cc: Can Guo <cang@codeaurora.org>
Cc: Asutosh Das <asutoshd@codeaurora.org>
Cc: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Change-Id: I896b9efee97133f78ac6d4f96047067a1ec886c0
Bug: 204438323
(cherry picked from commit 169f5eb288)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2021-11-03 13:31:33 -07:00
Bart Van Assche
3267cb1564 UPSTREAM: scsi: ufs: Optimize serialization of setup_xfer_req() calls
Reduce the number of times the host lock is taken in the hot path.
Additionally, inline ufshcd_vops_setup_xfer_req() because that function is
too short to keep it.

Link: https://lore.kernel.org/r/20210722033439.26550-13-bvanassche@acm.org
Fixes: a45f937110 ("scsi: ufs: Optimize host lock on transfer requests send/compl paths")
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Stanley Chu <stanley.chu@mediatek.com>
Cc: Can Guo <cang@codeaurora.org>
Cc: Bean Huo <beanhuo@micron.com>
Cc: Asutosh Das <asutoshd@codeaurora.org>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Change-Id: Id2a4b722160e277a0670c3ce4b066d695c816c9b
Bug: 204438323
(cherry picked from commit a024ad0d49)
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2021-11-03 13:31:33 -07:00
Bart Van Assche
679183fefa UPSTREAM: scsi: ufs: Revert "Utilize Transfer Request List Completion Notification Register"
Using the UTRLCNR register involves two MMIO accesses in the hot path while
using the doorbell register only involves a single MMIO access. Since MMIO
accesses take time, do not use the UTRLCNR register. The spinlock
contention on the SCSI host lock that is reintroduced by this commit will
be addressed later.

This reverts commit 6f71517296.

Link: https://lore.kernel.org/r/20210722033439.26550-12-bvanassche@acm.org
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Stanley Chu <stanley.chu@mediatek.com>
Cc: Can Guo <cang@codeaurora.org>
Cc: Asutosh Das <asutoshd@codeaurora.org>
Cc: Avri Altman <avri.altman@wdc.com>
Tested-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 1f522c5049)
Bug: 204438323
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I84888843e7d66ddc85cd97b181112d1f6606bd5a
2021-11-03 13:31:33 -07:00
Bart Van Assche
b98f9da669 UPSTREAM: scsi: ufs: Inline ufshcd_outstanding_req_clear()
Inline ufshcd_outstanding_req_clear() since it only has one caller and
since its body is only one line long.

Link: https://lore.kernel.org/r/20210722033439.26550-11-bvanassche@acm.org
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Stanley Chu <stanley.chu@mediatek.com>
Cc: Can Guo <cang@codeaurora.org>
Cc: Asutosh Das <asutoshd@codeaurora.org>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 815b9a27b0)
Bug: 204438323
Change-Id: I94b8ef9834f7efe4887a488eeb298e6a23727bba
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2021-11-03 13:31:33 -07:00
Bart Van Assche
3a5eed8fd7 UPSTREAM: scsi: ufs: Remove several wmb() calls
From arch/arm/include/asm/io.h

  #define __iowmb() wmb()
  [ ... ]
  #define writel(v,c) ({ __iowmb(); writel_relaxed(v,c); })

From Documentation/memory-barriers.txt: "Note that, when using writel(), a
prior wmb() is not needed to guarantee that the cache coherent memory
writes have completed before writing to the MMIO region."

In other words, calling wmb() before writel() is not necessary. Hence
remove the wmb() calls that precede a writel() call. Remove the wmb() calls
that precede a ufshcd_send_command() call since the latter function uses
writel(). Remove the wmb() call from ufshcd_wait_for_dev_cmd() since the
following chain of events guarantees that the CPU will see up-to-date LRB
values:

 - UFS controller writes to host memory.

 - UFS controller posts completion interrupt after the memory writes from
   the previous step are visible to the CPU.

 - complete(hba->dev_cmd.complete) is called from the UFS interrupt handler.

 - The wait_for_completion(hba->dev_cmd.complete) call in
   ufshcd_wait_for_dev_cmd() returns.

Link: https://lore.kernel.org/r/20210722033439.26550-10-bvanassche@acm.org
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Stanley Chu <stanley.chu@mediatek.com>
Cc: Can Guo <cang@codeaurora.org>
Cc: Asutosh Das <asutoshd@codeaurora.org>
Cc: Avri Altman <avri.altman@wdc.com>
Tested-by: Avri altman <avri.altman@wdc.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 3d2ac73d13)
Bug: 204438323
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: Ica6352b01e27b4a0fcee7dc9df44beab9139cc2c
2021-11-03 13:31:33 -07:00
Bart Van Assche
e011c72e8a UPSTREAM: scsi: ufs: Improve static type checking for the host controller state
Assign a name to the enumeration type for UFS host controller states and
remove the default clause from switch statements on this enumeration type
to make the compiler warn about unhandled enumeration labels.

Link: https://lore.kernel.org/r/20210722033439.26550-9-bvanassche@acm.org
Cc: Can Guo <cang@codeaurora.org>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Keoseong Park <keosung.park@samsung.com>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 9c202090ed)
Bug: 204438323
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I0756ae3a04caaa8b7584b847a57772f7bf6a771b
2021-11-03 13:31:33 -07:00
Bart Van Assche
506a024be7 UPSTREAM: scsi: ufs: Verify UIC locking requirements at runtime
Instead of documenting the locking requirements of the UIC code as
comments, use lockdep_assert_held() such that lockdep verifies the lockdep
requirements at runtime if lockdep is enabled.

Link: https://lore.kernel.org/r/20210722033439.26550-8-bvanassche@acm.org
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Stanley Chu <stanley.chu@mediatek.com>
Cc: Can Guo <cang@codeaurora.org>
Cc: Asutosh Das <asutoshd@codeaurora.org>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 35c7d874f5)
Bug: 204438323
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: Ifdc3d90bcdcfa43cda2d286295521666ccef4795
2021-11-03 13:31:33 -07:00
Bart Van Assche
73d9678ae5 UPSTREAM: scsi: ufs: Remove ufshcd_valid_tag()
scsi_add_host() allocates shost->can_queue tags. ufshcd_init() sets
shost->can_queue to hba->nutrs. In other words, we know that tag values
will less than hba->nutrs. Hence remove the checks that verify that
blk_get_request() returns a tag less than hba->nutrs. This check was
introduced by commit 14497328b6 ("scsi: ufs: verify command tag
validity").

Keep the tag >= 0 check because it helps to detect use-after-free issues.

Link: https://lore.kernel.org/r/20210722033439.26550-7-bvanassche@acm.org
CC: Avri Altman <avri.altman@wdc.com>
Cc: Alim Akhtar <alim.akhtar@samsung.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 4728ab4a8e)
Bug: 204438323
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I3c947ae3e2cce5712fd82fef9cfb937a80db0867
2021-11-03 13:31:32 -07:00
Bart Van Assche
a68b43f30a UPSTREAM: scsi: ufs: Use DECLARE_COMPLETION_ONSTACK() where appropriate
From Documentation/scheduler/completion.rst: "When a completion is declared
as a local variable within a function, then the initialization should
always use DECLARE_COMPLETION_ONSTACK() explicitly, not just to make
lockdep happy, but also to make it clear that limited scope had been
considered and is intentional."

Link: https://lore.kernel.org/r/20210722033439.26550-6-bvanassche@acm.org
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Stanley Chu <stanley.chu@mediatek.com>
Cc: Can Guo <cang@codeaurora.org>
Cc: Asutosh Das <asutoshd@codeaurora.org>
Cc: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 8a686f26ea)
Bug: 204438323
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I1e76702adc3df2e75e7a05fd06310f66d198b149
2021-11-03 13:31:32 -07:00
Bart Van Assche
f6429c2623 UPSTREAM: scsi: ufs: Rename the second ufshcd_probe_hba() argument
Rename the second argument of ufshcd_probe_hba() such that the name of that
argument reflects its purpose instead of how the function is called.  See
also commit 1b9e21412f ("scsi: ufs: Split ufshcd_probe_hba() based on its
called flow").

Link: https://lore.kernel.org/r/20210722033439.26550-5-bvanassche@acm.org
Cc: Asutosh Das <asutoshd@codeaurora.org>
Cc: Can Guo <cang@codeaurora.org>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 568dd99596)
Bug: 204438323
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I9a0fd3b787e6833511c1b4de9d6b50ea20580cd6
2021-11-03 13:31:32 -07:00
Bart Van Assche
1eec916379 UPSTREAM: scsi: ufs: Only include power management code if necessary
This patch slightly reduces the UFS driver size if built with power
management support disabled.

Link: https://lore.kernel.org/r/20210722033439.26550-4-bvanassche@acm.org
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Stanley Chu <stanley.chu@mediatek.com>
Cc: Can Guo <cang@codeaurora.org>
Cc: Asutosh Das <asutoshd@codeaurora.org>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 9bb25e5d9d)
Bug: 204438323
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: I80e4c124f546e2abb1b08444d0e2dc38546f4688
2021-11-03 13:31:32 -07:00
Bart Van Assche
bc35e28601 UPSTREAM: scsi: ufs: Reduce power management code duplication
Move the dev_get_drvdata() calls into the ufshcd_{system,runtime}_*()
functions. Remove ufshcd_runtime_idle() since it is empty. This patch does
not change any functionality.

Link: https://lore.kernel.org/r/20210722033439.26550-3-bvanassche@acm.org
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Stanley Chu <stanley.chu@mediatek.com>
Cc: Can Guo <cang@codeaurora.org>
Cc: Asutosh Das <asutoshd@codeaurora.org>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit f1ecbe1e54)
Bug: 204438323
Change-Id: Id3b811e95ba73daab642d68049b75cd1e96f85a2
Signed-off-by: Bart Van Assche <bvanassche@google.com>)
2021-11-03 13:31:32 -07:00
Martin K. Petersen
ed0d82c712 UPSTREAM: scsi: ufs: core: Use scsi_get_lba() to get LBA
Use the scsi_get_lba() helper instead of a function internal to the
SCSI disk driver. Remove #include "sd.h".

Link: https://lore.kernel.org/r/20210609033929.3815-16-martin.petersen@oracle.com
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Message-Id: <20210609033929.3815-16-martin.petersen@oracle.com>
(cherry picked from commit 5481508885)
Bug: 204438323
Signed-off-by: Bart Van Assche <bvanassche@google.com>
Change-Id: Ia0f0e62e7e1596065bd6011017bc6c4d5b28ca80
2021-11-03 13:31:32 -07:00