linux-2.6-microblaze.git
2 years agoscsi: mpi3mr: Fix kernel-doc
Jiapeng Chong [Wed, 25 May 2022 09:35:14 +0000 (17:35 +0800)]
scsi: mpi3mr: Fix kernel-doc

Fix the following W=1 kernel warnings:

drivers/scsi/mpi3mr/mpi3mr_app.c:1706: warning: expecting prototype for
adapter_state_show(). Prototype was for adp_state_show() instead.

Link: https://lore.kernel.org/r/20220525093514.55467-1-jiapeng.chong@linux.alibaba.com
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Add support for ATTO Fibre Channel devices
Bradley Grove [Tue, 24 May 2022 12:56:21 +0000 (08:56 -0400)]
scsi: lpfc: Add support for ATTO Fibre Channel devices

Update pci_device_id table and generate reporting strings for ATTO Celerity
and ThunderLink Fibre Channel devices.

Link: https://lore.kernel.org/r/20220524125621.47102-1-bgrove@attotech.com
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: James Smart <jsmart2021@gmail.com>
Co-developed-by: Jason Seba <jseba@attotech.com>
Signed-off-by: Jason Seba <jseba@attotech.com>
Signed-off-by: Bradley Grove <bgrove@attotech.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: core: Return BLK_STS_TRANSPORT for ALUA transitioning
Hannes Reinecke [Tue, 24 May 2022 05:56:31 +0000 (07:56 +0200)]
scsi: core: Return BLK_STS_TRANSPORT for ALUA transitioning

When the 'ALUA state transitioning' sense code is returned we cannot use
BLK_STS_AGAIN, as this has a very specific use-case.  So return
BLK_STS_TRANSPORT here.

Link: https://lore.kernel.org/r/20220524055631.85480-3-hare@suse.de
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: sd_zbc: Prevent zone information memory leak
Damien Le Moal [Wed, 1 Jun 2022 06:25:44 +0000 (15:25 +0900)]
scsi: sd_zbc: Prevent zone information memory leak

Make sure to always free a scsi disk zone information, even for regular
disks. This ensures that there is no memory leak, even in the case of a
zoned disk changing type to a regular disk (e.g. with a reformat using the
FORMAT WITH PRESET command or other vendor proprietary command).

To do this, rename sd_zbc_clear_zone_info() to sd_zbc_free_zone_info() and
remove sd_zbc_release_disk(). A call to sd_zbc_free_zone_info() is added to
sd_zbc_read_zones() for drives for which sd_is_zoned() returns
false. Furthermore, sd_zbc_free_zone_info() code make s sure that the sdkp
rev_mutex is never used while not being initialized by gating the cleanup
code with a a check on the zone_wp_update_buf field as it is never NULL
when rev_mutex has been initialized.

Link: https://lore.kernel.org/r/20220601062544.905141-3-damien.lemoal@opensource.wdc.com
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: sd: Fix potential NULL pointer dereference
Damien Le Moal [Wed, 1 Jun 2022 06:25:43 +0000 (15:25 +0900)]
scsi: sd: Fix potential NULL pointer dereference

If sd_probe() sees an early error before sdkp->device is initialized,
sd_zbc_release_disk() is called. This causes a NULL pointer dereference
when sd_is_zoned() is called inside that function. Avoid this by removing
the call to sd_zbc_release_disk() in sd_probe() error path.

This change is safe and does not result in zone information memory leakage
because the zone information for a zoned disk is allocated only when
sd_revalidate_disk() is called, at which point sdkp->disk_dev is fully set,
resulting in sd_disk_release() being called when needed to cleanup a disk
zone information using sd_zbc_release_disk().

Link: https://lore.kernel.org/r/20220601062544.905141-2-damien.lemoal@opensource.wdc.com
Fixes: 89d947561077 ("sd: Implement support for ZBC devices")
Reported-by: Dongliang Mu <mudongliangabcd@gmail.com>
Suggested-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Rework mrioc->bsg_device model to fix warnings
Sumit Saxena [Thu, 26 May 2022 17:01:57 +0000 (13:01 -0400)]
scsi: mpi3mr: Rework mrioc->bsg_device model to fix warnings

During driver unload, mrioc->bsg_device reference count becomes
negative. Also, as reported in [1], the driver's bsg_device model had few
more bugs. Fix all these up.

[1] https://marc.info/?l=linux-scsi&m=165183971411991&w=2

Link: https://lore.kernel.org/r/20220526170157.58274-1-sumit.saxena@broadcom.com
Fixes: 4268fa751365 ("scsi: mpi3mr: Add bsg device support")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Tested-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: myrb: Fix up null pointer access on myrb_cleanup()
Hannes Reinecke [Mon, 23 May 2022 12:02:44 +0000 (14:02 +0200)]
scsi: myrb: Fix up null pointer access on myrb_cleanup()

When myrb_probe() fails the callback might not be set, so we need to
validate the 'disable_intr' callback in myrb_cleanup() to not cause a null
pointer exception. And while at it do not call myrb_cleanup() if we cannot
enable the PCI device at all.

Link: https://lore.kernel.org/r/20220523120244.99515-1-hare@suse.de
Reported-by: Zheyu Ma <zheyuma97@gmail.com>
Tested-by: Zheyu Ma <zheyuma97@gmail.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: core: Unexport scsi_bus_type
Christoph Hellwig [Mon, 23 May 2022 08:38:38 +0000 (10:38 +0200)]
scsi: core: Unexport scsi_bus_type

scsi_bus_type is not used by any code outside of scsi_mod.ko.

Link: https://lore.kernel.org/r/20220523083838.227987-1-hch@lst.de
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: sd: Don't call blk_cleanup_disk() in sd_probe()
Christoph Hellwig [Mon, 23 May 2022 08:38:13 +0000 (10:38 +0200)]
scsi: sd: Don't call blk_cleanup_disk() in sd_probe()

In SCSI the midlayer has ownership of the request_queue, so on probe
failure we must only put the gendisk, but leave the request_queue alone.

Link: https://lore.kernel.org/r/20220523083813.227935-1-hch@lst.de
Fixes: 03252259e18e ("scsi: sd: Clean up gendisk if device_add_disk() failed")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ufs: ufshcd: Delete unnecessary NULL check
Dan Carpenter [Mon, 23 May 2022 08:28:18 +0000 (11:28 +0300)]
scsi: ufs: ufshcd: Delete unnecessary NULL check

The 'info' pointer points to somewhere in the middle of the 'hba' struct.
It can't possibly be NULL.  Delete the NULL check.

Link: https://lore.kernel.org/r/YotFotj43TkB8Rid@kili
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: isci: Fix typo in comment
Julia Lawall [Sat, 21 May 2022 11:11:41 +0000 (13:11 +0200)]
scsi: isci: Fix typo in comment

Spelling mistake (triple letters) in comment.  Detected with the help of
Coccinelle.

Link: https://lore.kernel.org/r/20220521111145.81697-91-Julia.Lawall@inria.fr
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: pmcraid: Fix typo in comment
Julia Lawall [Sat, 21 May 2022 11:11:39 +0000 (13:11 +0200)]
scsi: pmcraid: Fix typo in comment

Spelling mistake (triple letters) in comment.  Detected with the help of
Coccinelle.

Link: https://lore.kernel.org/r/20220521111145.81697-89-Julia.Lawall@inria.fr
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: smartpqi: Fix typo in comment
Julia Lawall [Sat, 21 May 2022 11:11:08 +0000 (13:11 +0200)]
scsi: smartpqi: Fix typo in comment

Spelling mistake (triple letters) in comment.  Detected with the help of
Coccinelle.

Link: https://lore.kernel.org/r/20220521111145.81697-58-Julia.Lawall@inria.fr
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: qedf: Fix typo in comment
Julia Lawall [Sat, 21 May 2022 11:11:25 +0000 (13:11 +0200)]
scsi: qedf: Fix typo in comment

Spelling mistake (triple letters) in comment.  Detected with the help of
Coccinelle.

Link: https://lore.kernel.org/r/20220521111145.81697-75-Julia.Lawall@inria.fr
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: esas2r: Fix typo in comment
Julia Lawall [Sat, 21 May 2022 11:10:50 +0000 (13:10 +0200)]
scsi: esas2r: Fix typo in comment

Spelling mistake (triple letters) in comment.  Detected with the help of
Coccinelle.

Link: https://lore.kernel.org/r/20220521111145.81697-40-Julia.Lawall@inria.fr
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: storvsc: Fix typo in comment
Julia Lawall [Sat, 21 May 2022 11:10:22 +0000 (13:10 +0200)]
scsi: storvsc: Fix typo in comment

Spelling mistake (triple letters) in comment.  Detected with the help of
Coccinelle.

Link: https://lore.kernel.org/r/20220521111145.81697-12-Julia.Lawall@inria.fr
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ufs: Split the drivers/scsi/ufs directory
Bart Van Assche [Wed, 11 May 2022 21:25:52 +0000 (14:25 -0700)]
scsi: ufs: Split the drivers/scsi/ufs directory

Split the drivers/scsi/ufs directory into 'core' and 'host' directories
under the drivers/ufs/ directory. Move shared header files into the
include/ufs/ directory. This separation makes it clear which header files
UFS drivers are allowed to include (include/ufs/*.h) and which header files
UFS drivers are not allowed to include (drivers/ufs/core/*.h).

Update the MAINTAINERS file. Add myself as a UFS reviewer.

Link: https://lore.kernel.org/r/20220511212552.655341-1-bvanassche@acm.org
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Avri Altman <avri.altman@wdc.com>
Cc: Bean Huo <beanhuo@micron.com>
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Keoseong Park <keosung.park@samsung.com>
Tested-by: Bean Huo <beanhuo@micron.com>
Tested-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Acked-by: Avri Altman <avri.altman@wdc.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: qla1280: Remove redundant variable
Colin Ian King [Wed, 18 May 2022 10:21:03 +0000 (11:21 +0100)]
scsi: qla1280: Remove redundant variable

Variable toke is being assigned a value that is never read. The variable is
redundant, remove it.

Cleans up clang scan build warning:
warning: Although the value stored to 'toke' is used in the enclosing
expression, the value is never actually read from 'toke'
[deadcode.DeadStores]

Link: https://lore.kernel.org/r/20220518102103.514701-1-colin.i.king@gmail.com
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Add support for VMID tagging of NVMe I/Os
James Smart [Thu, 19 May 2022 12:31:10 +0000 (05:31 -0700)]
scsi: lpfc: Add support for VMID tagging of NVMe I/Os

Modify the NVMe I/O path to look for VMID support and call the transport to
obtain the I/O's appid value.

Link: https://lore.kernel.org/r/20220519123110.17361-5-jsmart2021@gmail.com
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Co-developed-by: Gaurav Srivastava <gaurav.srivastava@broadcom.com>
Signed-off-by: Gaurav Srivastava <gaurav.srivastava@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Rework lpfc_vmid_get_appid() to be protocol independent
James Smart [Thu, 19 May 2022 12:31:09 +0000 (05:31 -0700)]
scsi: lpfc: Rework lpfc_vmid_get_appid() to be protocol independent

Rework lpfc_vmid_get_appid() arguments to remove scsi_cmnd dependency. The
function is now callable by the NVMe I/O path. Fix up SCSI call path to
accommodate the arg change.

Link: https://lore.kernel.org/r/20220519123110.17361-4-jsmart2021@gmail.com
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Co-developed-by: Gaurav Srivastava <gaurav.srivastava@broadcom.com>
Signed-off-by: Gaurav Srivastava <gaurav.srivastava@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Commonize VMID code location
James Smart [Thu, 19 May 2022 12:31:08 +0000 (05:31 -0700)]
scsi: lpfc: Commonize VMID code location

Remove VMID code from its SCSI-specific location and move to a new file
solely for VMID code.

Link: https://lore.kernel.org/r/20220519123110.17361-3-jsmart2021@gmail.com
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Co-developed-by: Gaurav Srivastava <gaurav.srivastava@broadcom.com>
Signed-off-by: Gaurav Srivastava <gaurav.srivastava@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: nvme-fc: Add new routine nvme_fc_io_getuuid()
Muneendra Kumar [Thu, 19 May 2022 12:31:07 +0000 (05:31 -0700)]
scsi: nvme-fc: Add new routine nvme_fc_io_getuuid()

Add nvme_fc_io_getuuid() to the nvme-fc transport. The routine is invoked
by the FC LLDD on a per-I/O request basis.  The routine translates from the
FC-specific request structure to the bio and the cgroup structure in order
to obtain the FC appid stored in the cgroup structure. If a value is not
set or a bio is not found, a NULL appid (aka uuid) will be returned to the
LLDD.

Link: https://lore.kernel.org/r/20220519123110.17361-2-jsmart2021@gmail.com
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Muneendra Kumar <muneendra.kumar@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: target: tcmu: Avoid holding XArray lock when calling lock_page
Bodo Stroesser [Tue, 17 May 2022 19:29:13 +0000 (21:29 +0200)]
scsi: target: tcmu: Avoid holding XArray lock when calling lock_page

In tcmu_blocks_release(), lock_page() is called to prevent a race causing
possible data corruption. Since lock_page() might sleep, calling it while
holding XArray lock is a bug.

To fix this, replace the xas_for_each() call with xa_for_each_range().
Since the latter does its own handling of XArray locking, the xas_lock()
and xas_unlock() calls around the original loop are no longer necessary.

The switch to xa_for_each_range() slows down the loop slightly. This is
acceptable since tcmu_blocks_release() is not relevant for performance.

Link: https://lore.kernel.org/r/20220517192913.21405-1-bostroesser@gmail.com
Fixes: bb9b9eb0ae2e ("scsi: target: tcmu: Fix possible data corruption")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Bodo Stroesser <bostroesser@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: elx: efct: Remove NULL check after calling container_of()
Haowen Bai [Tue, 17 May 2022 01:25:36 +0000 (09:25 +0800)]
scsi: elx: efct: Remove NULL check after calling container_of()

container_of() will never return NULL.

Link: https://lore.kernel.org/r/1652750737-22673-1-git-send-email-baihaowen@meizu.com
Signed-off-by: Haowen Bai <baihaowen@meizu.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: dpt_i2o: Drop redundant spinlock initialization
Haowen Bai [Tue, 10 May 2022 09:47:03 +0000 (17:47 +0800)]
scsi: dpt_i2o: Drop redundant spinlock initialization

adpt_post_wait_lock was declared and initialized by DEFINE_SPINLOCK so we
don't need to call spin_lock_init(). Drop the call.

Link: https://lore.kernel.org/r/1652176024-3981-1-git-send-email-baihaowen@meizu.com
Signed-off-by: Haowen Bai <baihaowen@meizu.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: qedf: Remove redundant variable op
Colin Ian King [Tue, 17 May 2022 09:25:18 +0000 (10:25 +0100)]
scsi: qedf: Remove redundant variable op

The variable 'op' is assigned a value and is never read. The variable is
not used and is redundant, remove it.

Link: https://lore.kernel.org/r/20220517092518.93159-1-colin.i.king@gmail.com
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: hisi_sas: Fix memory ordering in hisi_sas_task_deliver()
John Garry [Tue, 17 May 2022 08:04:21 +0000 (16:04 +0800)]
scsi: hisi_sas: Fix memory ordering in hisi_sas_task_deliver()

The memories for the slot should be observed to be written prior to
observing the slot as ready.

Prior to commit 26fc0ea74fcb ("scsi: libsas: Drop SAS_TASK_AT_INITIATOR"),
we had a spin_lock() + spin_unlock() immediately before marking the slot as
ready. The spin_unlock() - with release semantics - caused the slot memory
to be observed to be written.

Now that the spin_lock() + spin_unlock() is gone, use a smp_wmb().

Link: https://lore.kernel.org/r/1652774661-12935-1-git-send-email-john.garry@huawei.com
Fixes: 26fc0ea74fcb ("scsi: libsas: Drop SAS_TASK_AT_INITIATOR")
Reported-by: Yihang Li <liyihang6@hisilicon.com>
Tested-by: Yihang Li <liyihang6@hisilicon.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: fnic: Replace DMA mask of 64 bits with 47 bits
Karan Tilak Kumar [Fri, 13 May 2022 20:56:05 +0000 (13:56 -0700)]
scsi: fnic: Replace DMA mask of 64 bits with 47 bits

Cisco VIC supports only 47 bits.  If the host sends DMA addresses that are
greater than 47 bits, it causes work queue (WQ) errors in the VIC.

Link: https://lore.kernel.org/r/20220513205605.81788-1-kartilak@cisco.com
Tested-by: Karan Tilak Kumar <kartilak@cisco.com>
Co-developed-by: Dhanraj Jhawar <djhawar@cisco.com>
Signed-off-by: Dhanraj Jhawar <djhawar@cisco.com>
Co-developed-by: Sesidhar Baddela <sebaddel@cisco.com>
Signed-off-by: Sesidhar Baddela <sebaddel@cisco.com>
Signed-off-by: Arulprabhu Ponnusamy <arulponn@cisco.com>
Signed-off-by: Karan Tilak Kumar <kartilak@cisco.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Add target device related sysfs attributes
Sreekanth Reddy [Tue, 17 May 2022 11:53:10 +0000 (17:23 +0530)]
scsi: mpi3mr: Add target device related sysfs attributes

Add sysfs attributes for exposing target device details such as SAS
address, firmware device handle, and persistent ID for the
controller-attached devices and RAID volumes.

Link: https://lore.kernel.org/r/20220517115310.13062-3-sreekanth.reddy@broadcom.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Add shost related sysfs attributes
Sreekanth Reddy [Tue, 17 May 2022 11:53:09 +0000 (17:23 +0530)]
scsi: mpi3mr: Add shost related sysfs attributes

Add shost related sysfs attributes to display the controller's firmware
version, queue depth, number of requests, and number of reply queues. Also
add an attribute to set & get the logging_level.

Link: https://lore.kernel.org/r/20220517115310.13062-2-sreekanth.reddy@broadcom.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: elx: efct: Remove redundant memset() statement
Harshit Mogalapalli [Thu, 5 May 2022 14:36:57 +0000 (07:36 -0700)]
scsi: elx: efct: Remove redundant memset() statement

As memset() of bmbx is immediately followed by a memcpy() where bmbx is the
destination, the memset() is redundant.

Link: https://lore.kernel.org/r/20220505143703.45441-1-harshit.m.mogalapalli@oracle.com
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: megaraid_sas: Remove redundant memset() statement
Harshit Mogalapalli [Thu, 5 May 2022 14:32:13 +0000 (07:32 -0700)]
scsi: megaraid_sas: Remove redundant memset() statement

As memset() of scmd->sense_buffer is immediately followed by a memcpy()
where scmd->sense_buffer is the destination. The memset() is redundant.

Link: https://lore.kernel.org/r/20220505143214.44908-1-harshit.m.mogalapalli@oracle.com
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Return error if dma_alloc_coherent() fails
Dan Carpenter [Thu, 5 May 2022 10:25:52 +0000 (13:25 +0300)]
scsi: mpi3mr: Return error if dma_alloc_coherent() fails

Return -ENOMEM instead of success if dma_alloc_coherent() fails.

Link: https://lore.kernel.org/r/YnOmMGHqCOtUCYQ1@kili
Fixes: 43ca11005098 ("scsi: mpi3mr: Add support for PEL commands")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: hisi_sas: Fix rescan after deleting a disk
John Garry [Thu, 12 May 2022 11:15:34 +0000 (19:15 +0800)]
scsi: hisi_sas: Fix rescan after deleting a disk

Removing an ATA device via sysfs means that the device may not be found
through re-scanning:

root@ubuntu:/home/john# lsscsi
[0:0:0:0] disk SanDisk LT0200MO P404 /dev/sda
[0:0:1:0] disk ATA HGST HUS724040AL A8B0 /dev/sdb
[0:0:8:0] enclosu 12G SAS Expander RevB -
root@ubuntu:/home/john# echo 1 > /sys/block/sdb/device/delete
root@ubuntu:/home/john# echo "- - -" > /sys/class/scsi_host/host0/scan
root@ubuntu:/home/john# lsscsi
[0:0:0:0] disk SanDisk LT0200MO P404 /dev/sda
[0:0:8:0] enclosu 12G SAS Expander RevB -
root@ubuntu:/home/john#

The problem is that the rescan of the device may conflict with the device
in being re-initialized, as follows:

 - In the rescan we call hisi_sas_slave_alloc() in store_scan() ->
   sas_user_scan() -> [__]scsi_scan_target() -> scsi_probe_and_add_lunc()
   -> scsi_alloc_sdev() -> hisi_sas_slave_alloc() -> hisi_sas_init_device()
   In hisi_sas_init_device() we issue an IT nexus reset for ATA devices

 - That IT nexus causes the remote PHY to go down and this triggers a bcast
   event

 - In parallel libsas processes the bcast event, finds that the phy is down
   and marks the device as gone

The hard reset issued in hisi_sas_init_device() is unncessary - as
described in the code comment - so remove it. Also set dev status as
HISI_SAS_DEV_NORMAL as the hisi_sas_init_device() call.

Link: https://lore.kernel.org/r/1652354134-171343-4-git-send-email-john.garry@huawei.com
Fixes: 36c6b7613ef1 ("scsi: hisi_sas: Initialise devices in .slave_alloc callback")
Tested-by: Yihang Li <liyihang6@hisilicon.com>
Reviewed-by: Xiang Chen <chenxiang66@hisilicon.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: hisi_sas: Use sas_ata_wait_after_reset() in IT nexus reset
John Garry [Thu, 12 May 2022 11:15:33 +0000 (19:15 +0800)]
scsi: hisi_sas: Use sas_ata_wait_after_reset() in IT nexus reset

We have seen errors like this when a SATA device is probed:

[524.566298] hisi_sas_v3_hw 0000L74:02.0: erroneous completion iptt=4096 ...
[524.582827] sas: TMF task open reject failed 500e004aaaaaaaa00

Since commit 21c7e972475e ("scsi: hisi_sas: Disable SATA disk phy for
severe I_T nexus reset failure"), we issue an ATA softreset to disks after
a phy reset to ensure that they are in sound working order. If the
softreset is issued before the remote phy has come back up then the
softreset will fail (errors as above). Remedy this by waiting for the phy
to come back up after the reset.

Link: https://lore.kernel.org/r/1652354134-171343-3-git-send-email-john.garry@huawei.com
Tested-by: Yihang Li <liyihang6@hisilicon.com>
Reviewed-by: Xiang Chen <chenxiang66@hisilicon.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: libsas: Refactor sas_ata_hard_reset()
John Garry [Thu, 12 May 2022 11:15:32 +0000 (19:15 +0800)]
scsi: libsas: Refactor sas_ata_hard_reset()

Create function sas_ata_wait_after_reset() from sas_ata_hard_reset() as
some LLDDs may want to check for a remote ATA phy is up after reset.

Link: https://lore.kernel.org/r/1652354134-171343-2-git-send-email-john.garry@huawei.com
Tested-by: Yihang Li <liyihang6@hisilicon.com>
Reviewed-by: Xiang Chen <chenxiang66@hisilicon.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpt3sas: Update driver version to 42.100.00.00
Sreekanth Reddy [Wed, 11 May 2022 07:26:21 +0000 (12:56 +0530)]
scsi: mpt3sas: Update driver version to 42.100.00.00

Update driver version to 42.100.00.00.

Link: https://lore.kernel.org/r/20220511072621.30657-2-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpt3sas: Fix junk chars displayed while printing ChipName
Sreekanth Reddy [Wed, 11 May 2022 07:26:20 +0000 (12:56 +0530)]
scsi: mpt3sas: Fix junk chars displayed while printing ChipName

Terminate string after copying 16 bytes of ChipName data from Manufacturing
Page0 to prevent %s from printing junk characters.

Link: https://lore.kernel.org/r/20220511072621.30657-1-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ipr: Use kobj_to_dev()
Minghao Chi [Tue, 10 May 2022 10:51:13 +0000 (10:51 +0000)]
scsi: ipr: Use kobj_to_dev()

Use kobj_to_dev() instead of open-coding it.

Link: https://lore.kernel.org/r/20220510105113.1351891-1-chi.minghao@zte.com.cn
Reported-by: Zeal Robot <zealci@zte.com.cn>
Acked-by: Brian King <brking@linux.vnet.ibm.com>
Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Fix a NULL vs IS_ERR() bug in mpi3mr_bsg_init()
Dan Carpenter [Fri, 6 May 2022 13:17:33 +0000 (16:17 +0300)]
scsi: mpi3mr: Fix a NULL vs IS_ERR() bug in mpi3mr_bsg_init()

The bsg_setup_queue() function does not return NULL.  It returns error
pointers.  Fix the check accordingly.

Link: https://lore.kernel.org/r/YnUf7RQl+A3tigWh@kili
Fixes: 4268fa751365 ("scsi: mpi3mr: Add bsg device support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: bnx2fc: Avoid using get_cpu() in bnx2fc_cmd_alloc()
Sebastian Andrzej Siewior [Fri, 6 May 2022 10:57:58 +0000 (12:57 +0200)]
scsi: bnx2fc: Avoid using get_cpu() in bnx2fc_cmd_alloc()

Using get_cpu() leads to disabling preemption and in this context it is not
possible to acquire the following spinlock_t on PREEMPT_RT because it
becomes a sleeping lock.

Commit 0ea5c27583e1 ("[SCSI] bnx2fc: common free list for cleanup
commands") says that it is using get_cpu() as a fix in case the CPU is
preempted.  While this might be true, the important part is that it is now
using the same CPU for locking and unlocking while previously it always
relied on smp_processor_id().  The date structure itself is protected with
a lock so it does not rely on CPU-local access.

Replace get_cpu() with raw_smp_processor_id() to obtain the current CPU
number which is used as an index for the per-CPU resource.

Link: https://lore.kernel.org/r/20220506105758.283887-5-bigeasy@linutronix.de
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: libfc: Remove get_cpu() semantics in fc_exch_em_alloc()
Davidlohr Bueso [Fri, 6 May 2022 10:57:57 +0000 (12:57 +0200)]
scsi: libfc: Remove get_cpu() semantics in fc_exch_em_alloc()

The get_cpu() in fc_exch_em_alloc() was introduced in commit f018b73af6db
("[SCSI] libfc, libfcoe, fcoe: use smp_processor_id() only when preempt
disabled") for no other reason than to simply use smp_processor_id()
without getting a warning, because everything is done with the pool->lock
held anyway.  However, get_cpu(), by disabling preemption, does not play
well with PREEMPT_RT, particularly when acquiring a regular (and thus
sleepable) spinlock.

Therefore remove the get_cpu() and just use the unstable value as we will
have CPU locality guarantees next by taking the lock.  The window of
migration, as noted by Sebastian, is small and even if it happens the
result is correct.

Link: https://lore.kernel.org/r/20211117025956.79616-2-dave@stgolabs.net
Link: https://lore.kernel.org/r/20220506105758.283887-4-bigeasy@linutronix.de
Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: fcoe: Use per-CPU API to update per-CPU statistics
Sebastian Andrzej Siewior [Fri, 6 May 2022 10:57:56 +0000 (12:57 +0200)]
scsi: fcoe: Use per-CPU API to update per-CPU statistics

The per-CPU statistics (struct fc_stats) is updated by getting a stable
per-CPU pointer via get_cpu() + per_cpu_ptr() and then performing the
increment. This can be optimized by using this_cpu_*() which will do
whatever is needed on the architecture to perform the update safe and
efficient.  The read out of the individual value (fc_get_host_stats())
should be done by using READ_ONCE() instead of a plain-C access. The
difference is that READ_ONCE() will always perform a single access while
the plain-C access can be split by the compiler into two loads if it
appears beneficial.  The usage of u64 has the side-effect that it is also
64bit wide on 32bit architectures and the read is always split into two
loads. The can lead to strange values if the read happens during an update
which alters both 32bit parts of the 64bit value. This can be circumvented
by either using a 32bit variables on 32bit architecures or extending the
statistics with a sequence counter.

Use this_cpu_*() API to update the statistics and READ_ONCE() to read it.

Link: https://lore.kernel.org/r/20220506105758.283887-3-bigeasy@linutronix.de
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: fcoe: Add a local_lock to fcoe_percpu
Davidlohr Bueso [Fri, 6 May 2022 10:57:55 +0000 (12:57 +0200)]
scsi: fcoe: Add a local_lock to fcoe_percpu

fcoe_get_paged_crc_eof() relies on the caller having preemption disabled to
ensure the per-CPU fcoe_percpu context remains valid throughout the
call. This is done by either holding spinlocks (such as bnx2fc_global_lock
or qedf_global_lock) or the get_cpu() from fcoe_alloc_paged_crc_eof(). This
last one breaks PREEMPT_RT semantics as there can be memory allocation and
end up sleeping in atomic contexts.

Introduce a local_lock_t to struct fcoe_percpu that will keep the non-RT
case the same, mapping to preempt_disable/enable, while RT will use a
per-CPU spinlock allowing the region to be preemptible but still maintain
CPU locality. The other users of fcoe_percpu are already safe in this
regard and do not require local_lock()ing.

Link: https://lore.kernel.org/r/20211117025956.79616-3-dave@stgolabs.net
Link: https://lore.kernel.org/r/20220506105758.283887-2-bigeasy@linutronix.de
Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: target: iscsi: Rename iscsi_session to iscsit_session
Max Gurtovoy [Thu, 28 Apr 2022 09:29:39 +0000 (12:29 +0300)]
scsi: target: iscsi: Rename iscsi_session to iscsit_session

The structure iscsi_session naming is used by the iSCSI initiator
driver. Rename the target session to iscsit_session to have more readable
code.

Link: https://lore.kernel.org/r/20220428092939.36768-3-mgurtovoy@nvidia.com
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: target: iscsi: Rename iscsi_conn to iscsit_conn
Max Gurtovoy [Thu, 28 Apr 2022 09:29:38 +0000 (12:29 +0300)]
scsi: target: iscsi: Rename iscsi_conn to iscsit_conn

The structure iscsi_conn naming is used by the iSCSI initiator
driver. Rename the target conn to iscsit_conn to have more readable code.

Link: https://lore.kernel.org/r/20220428092939.36768-2-mgurtovoy@nvidia.com
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: target: iscsi: Rename iscsi_cmd to iscsit_cmd
Max Gurtovoy [Thu, 28 Apr 2022 09:29:37 +0000 (12:29 +0300)]
scsi: target: iscsi: Rename iscsi_cmd to iscsit_cmd

The structure iscsi_cmd naming is used by the iSCSI initiator driver.
Rename the target cmd to iscsit_cmd to have more readable code.

Link: https://lore.kernel.org/r/20220428092939.36768-1-mgurtovoy@nvidia.com
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Return I/Os to an unrecoverable HBA with DID_ERROR
Sreekanth Reddy [Thu, 5 May 2022 18:48:06 +0000 (00:18 +0530)]
scsi: mpi3mr: Return I/Os to an unrecoverable HBA with DID_ERROR

Complete all new I/O requests issued to an unrecoverable controller with
DID_ERROR status instead of returning the I/O requests with
SCSI_MLQUEUE_HOST_BUSY. This will prevent the infinite retries of the new
I/Os when a controller is in an unrecoverable state.

Link: https://lore.kernel.org/r/20220505184808.24049-1-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Hidden drives not removed during soft reset
Sreekanth Reddy [Thu, 5 May 2022 18:48:07 +0000 (00:18 +0530)]
scsi: mpi3mr: Hidden drives not removed during soft reset

If any drive is missing during reset, the driver checks whether the device
is exposed to the OS. If it is, then it removes the device from the OS and
its own internal list. For hidden devices, even if they are found as
missing during reset, the driver is not removing them from its internal
list.

Modify driver to remove hidden devices from the driver's target device list
if they are missing during soft reset.

Link: https://lore.kernel.org/r/20220505184808.24049-2-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Increase I/O timeout value to 60s
Sreekanth Reddy [Thu, 5 May 2022 18:48:08 +0000 (00:18 +0530)]
scsi: mpi3mr: Increase I/O timeout value to 60s

Set each SCSI device's default I/O timeout and default error handling I/O
timeout to 60s.

Link: https://lore.kernel.org/r/20220505184808.24049-3-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Update lpfc version to 14.2.0.3
James Smart [Fri, 6 May 2022 03:55:19 +0000 (20:55 -0700)]
scsi: lpfc: Update lpfc version to 14.2.0.3

Update lpfc version to 14.2.0.3

Link: https://lore.kernel.org/r/20220506035519.50908-13-jsmart2021@gmail.com
Co-developed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Use sg_dma_address() and sg_dma_len() macros for NVMe I/O
James Smart [Fri, 6 May 2022 03:55:18 +0000 (20:55 -0700)]
scsi: lpfc: Use sg_dma_address() and sg_dma_len() macros for NVMe I/O

NVMe I/O problems may be seen on IOMMU enabled platforms. Adapter I/Os
failing with transfer length mismatches.

The sg list processing routine for NVMe I/O is accessing the sg entry
directly for the length and address fields. On some IOMMU platforms,
contigous mappings are compressed to the first sg entry with the sum of the
lengths set to the sg entry dma_length field. The length fields are left
for later use by the unmap call. As such, the driver didn't see the actual
dma_length value, just the first entries length value.  Drivers are to use
the sg_dma_length() and sg_dma_address() macros to reference the sg
entry. The macros select the proper length field (dma_length or length) to
reference.

Fix the offending code to use the sg_dma_xxx macros.

Link: https://lore.kernel.org/r/20220506035519.50908-12-jsmart2021@gmail.com
Tested-by: Jerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Co-developed-by: Nigel Kirkland <nkirkland2304@gmail.com>
Signed-off-by: Nigel Kirkland <nkirkland2304@gmail.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Alter FPIN stat accounting logic
James Smart [Fri, 6 May 2022 03:55:17 +0000 (20:55 -0700)]
scsi: lpfc: Alter FPIN stat accounting logic

When configuring CMF management based on signals instead of FPINs, FPIN
alarm and warning statistics are not tracked.

Change the behavior so that FPIN alarms and warnings are always tracked
regardless of the configured mode.

Similar changes are made in the CMF signal stat accounting logic.  Upon
receipt of a signal, only track signaled alarms and warnings. FPIN stats
should not be incremented upon receipt of a signal.

Link: https://lore.kernel.org/r/20220506035519.50908-11-jsmart2021@gmail.com
Co-developed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Rework FDMI initialization after link up
James Smart [Fri, 6 May 2022 03:55:16 +0000 (20:55 -0700)]
scsi: lpfc: Rework FDMI initialization after link up

After a link up, it's possible for the switch to change FDMI support (e.g.
FDMI1 vs FDMI2 vs SmartSAN).  If the switch reverts to FDMI1, then the
revert is currently not detected.

Additionally, when NPIV is configured, it's possible the physical port's
RHBA is unprocessed by the switch before reciept of an NPIV port issued
RPRT.  This causes some switches vendors to reject the NPIV's RPRT.

Fix by reinitializing base FDMI mode on link up, and defer FDMI vport RPRT
submission until after confirming physical port's RHBA is completed.

Link: https://lore.kernel.org/r/20220506035519.50908-10-jsmart2021@gmail.com
Co-developed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Change VMID registration to be based on fabric parameters
James Smart [Fri, 6 May 2022 03:55:15 +0000 (20:55 -0700)]
scsi: lpfc: Change VMID registration to be based on fabric parameters

Currently, VMID registration is configured via module parameters.  This
could lead to VMID compatibility issues if two ports are connected to
different brands of switches, as the two brands implement VMID differently.

Make logical changes so that VMID registration is based on common service
parameters from FLOGI_ACC with fabric rather than module parameters.

Link: https://lore.kernel.org/r/20220506035519.50908-9-jsmart2021@gmail.com
Co-developed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Decrement outstanding gidft_inp counter if lpfc_err_lost_link()
James Smart [Fri, 6 May 2022 03:55:14 +0000 (20:55 -0700)]
scsi: lpfc: Decrement outstanding gidft_inp counter if lpfc_err_lost_link()

During large NPIV port testing, it was sometimes seen that not all vports
would log back in to the target device.

There are instances when the fabric is slow to respond to a spam of GID_PT
requests and as a result the SLI PORT may abort the GID_PT request because
the fabric takes so long.  lpfc_cmpl_ct_cmd_gid_pt() would enter the
lpfc_err_lost_link() logic and attempt to lpfc_els_flush_rscn(), which is
fine, but forgets to decrement the gidft_inp counter.  This results in a
vport->gidft_inp never reaching 0 and never restarting discovery again.

Decrement vport->gidft_inp if lpfc_err_lost_link() is true for both
lpfc_cmpl_ct_cmd_gid_pt() and lpfc_cmpl_ct_cmd_gid_ft().

Increase logging info during RSCN timeout and lpfc_err_lost_link() events.

Link: https://lore.kernel.org/r/20220506035519.50908-8-jsmart2021@gmail.com
Co-developed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Use list_for_each_entry_safe() in rscn_recovery_check()
James Smart [Fri, 6 May 2022 03:55:13 +0000 (20:55 -0700)]
scsi: lpfc: Use list_for_each_entry_safe() in rscn_recovery_check()

In GID_PT mode with lpfc_ns_query=1, a race condition between iterating the
vport->fc_nodes list in lpfc_rscn_recovery_check() and cleanup of an ndlp
can trigger a crash while processing the RSCN of another initiator from the
same zone.

During iteration of the vport->fc_nodes list, an ndlp is cleaned up and
released. lpfc_dequeue_node() is called from lpfc_cleanup_node() leading to
a bad ndlp dereference in lpfc_rscn_recovery_check().

Change list_for_each_entry() to list_for_each_entry_safe() in
lpfc_rscn_recovery_check() to protect against removal of an initiator ndlp,
while walking the vport->fc_nodes list.

Link: https://lore.kernel.org/r/20220506035519.50908-7-jsmart2021@gmail.com
Co-developed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Fix dmabuf ptr assignment in lpfc_ct_reject_event()
James Smart [Fri, 6 May 2022 03:55:12 +0000 (20:55 -0700)]
scsi: lpfc: Fix dmabuf ptr assignment in lpfc_ct_reject_event()

Upon driver receipt of a CT cmd for type = 0xFA (Management Server) and
subtype = 0x11 (Fabric Device Management Interface), the driver is
responding with garbage CT cmd data when it should send a properly formed
RJT.

The __lpfc_prep_xmit_seq64_s4() routine was using the wrong buffer for the
reject.

Fix by converting the routine to use the buffer specified in the bde within
the wqe rather than the ill-set bmp element.

Link: https://lore.kernel.org/r/20220506035519.50908-6-jsmart2021@gmail.com
Fixes: 61910d6a5243 ("scsi: lpfc: SLI path split: Refactor CT paths")
Co-developed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Inhibit aborts if external loopback plug is inserted
James Smart [Fri, 6 May 2022 03:55:11 +0000 (20:55 -0700)]
scsi: lpfc: Inhibit aborts if external loopback plug is inserted

After running a short external loopback test, when the external loopback is
removed and a normal cable inserted that is directly connected to a target
device, the system oops in the llpfc_set_rrq_active() routine.

When the loopback was inserted an FLOGI was transmit. As we're looped back,
we receive the FLOGI request. The FLOGI is ABTS'd as we recognize the same
wppn thus understand it's a loopback. However, as the ABTS sends address
information the port is not set to (fffffe), the ABTS is dropped on the
wire. A short 1 frame loopback test is run and completes before the ABTS
times out. The looback is unplugged and the new cable plugged in, and the
an FLOGI to the new device occurs and completes. Due to a mixup in ref
counting the completion of the new FLOGI releases the fabric ndlp. Then the
original ABTS completes and references the released ndlp generating the
oops.

Correct by no-op'ing the ABTS when in loopback mode (it will be dropped
anyway). Added a flag to track the mode to recognize when it should be
no-op'd.

Link: https://lore.kernel.org/r/20220506035519.50908-5-jsmart2021@gmail.com
Co-developed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Fix ndlp put following a LOGO completion
James Smart [Fri, 6 May 2022 03:55:10 +0000 (20:55 -0700)]
scsi: lpfc: Fix ndlp put following a LOGO completion

During testing with repeated asynchronous resets of the target, an issue
was found when the driver issues a LOGO to disconnect its login and recover
all exchanges. The LOGO command takes a node reference but neglects to
remove it, keeping the node reference count artifically high.

Add a call to lpfc_nlp_put() to lpfc_nlp_logo_unreg() and move the mempool
free call to the routine exit along with the needed put.  This is always
safe as this will not be the last reference removed as lpfc_unreg_rpi()
ensures there is an additional reference on the ndlp.

Link: https://lore.kernel.org/r/20220506035519.50908-4-jsmart2021@gmail.com
Co-developed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Fill in missing ndlp kref puts in error paths
James Smart [Fri, 6 May 2022 03:55:09 +0000 (20:55 -0700)]
scsi: lpfc: Fill in missing ndlp kref puts in error paths

Code review, following every lpfc_nlp_get() call vs calls during error
handling, discovered cases of missing put calls.

Correct by adding ndlp kref puts in the respective error paths.

Also added comments to several of the error paths to record relationships
to reference counts.

Link: https://lore.kernel.org/r/20220506035519.50908-3-jsmart2021@gmail.com
Co-developed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Fix element offset in __lpfc_sli_release_iocbq_s4()
James Smart [Fri, 6 May 2022 03:55:08 +0000 (20:55 -0700)]
scsi: lpfc: Fix element offset in __lpfc_sli_release_iocbq_s4()

The prior commit that moved from iocb elements to explicit wqe elements
missed a name change.

Correct __lpfc_sli_release_iocbq_s4() to reference wqe rather than iocb.

Link: https://lore.kernel.org/r/20220506035519.50908-2-jsmart2021@gmail.com
Fixes: a680a9298e7b ("scsi: lpfc: SLI path split: Refactor lpfc_iocbq")
Co-developed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ufs: ufshpb: Clean up ufshpb_suspend()/resume()
Bean Huo [Thu, 5 May 2022 13:47:07 +0000 (15:47 +0200)]
scsi: ufs: ufshpb: Clean up ufshpb_suspend()/resume()

ufshpb_resume() is only called when the HPB state is HPB_SUSPEND, so the
check statement for "ufshpb_get_state(hpb) != HPB_PRESENT" is useless.

Link: https://lore.kernel.org/r/20220505134707.35929-7-huobean@gmail.com
Reviewed-by: Keoseong Park <keosung.park@samsung.com>
Signed-off-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ufs: ufshpb: Add handing of device reset regions in HPB device mode
Bean Huo [Thu, 5 May 2022 13:47:06 +0000 (15:47 +0200)]
scsi: ufs: ufshpb: Add handing of device reset regions in HPB device mode

In UFS HPB Spec JESD220-3A,

"5.8. Active and inactive information upon power cycle
...
When the device is powered off by the host, the device may restore L2P map
data upon power up or build from the host's HPB READ command. In case
device powered up and lost HPB information, device can signal to the host
through HPB Sense data, by setting HPB Operation as '2' which will inform
the host that device reset HPB information."

Therefore, for HPB device control mode, if the UFS device is reset via the
RST_N pin, the active region information in the device will be reset. If
the host side receives this notification from the device side, it is
recommended to inactivate all active regions in the host's HPB cache.

Link: https://lore.kernel.org/r/20220505134707.35929-6-huobean@gmail.com
Reviewed-by: Keoseong Park <keosung.park@samsung.com>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Signed-off-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ufs: ufshpb: Change sysfs node hpb_stats/rb_* prefix to start with rcmd_*
Bean Huo [Thu, 5 May 2022 13:47:05 +0000 (15:47 +0200)]
scsi: ufs: ufshpb: Change sysfs node hpb_stats/rb_* prefix to start with rcmd_*

According to the documentation of the sysfs nodes rb_noti_cnt,
rb_active_cnt and rb_inactive_cnt, these are all related to HPB
recommendation in UPIU response packet. 'rcmd' (recommendation) should be
the correct abbreviation.

Change the sysfs documentation about these sysfs nodes to highlight what
they mean under different HPB control modes.

Link: https://lore.kernel.org/r/20220505134707.35929-5-huobean@gmail.com
Reviewed-by: Keoseong Park <keosung.park@samsung.com>
Signed-off-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ufs: ufshpb: Clean up the handler when device resets HPB information
Bean Huo [Thu, 5 May 2022 13:47:04 +0000 (15:47 +0200)]
scsi: ufs: ufshpb: Clean up the handler when device resets HPB information

"When the device is powered off by the host, the device may restore L2P map
data upon power up or build from the host's HPB READ command. In case
device powered up and lost HPB information, device can signal to the host
through HPB Sense data, by setting HPB Operation as '2' which will inform
the host that device reset HPB information."

Clean up the handler and make the intent of this handler more readable, no
functional change.

Link: https://lore.kernel.org/r/20220505134707.35929-4-huobean@gmail.com
Reviewed-by: Keoseong Park <keosung.park@samsung.com>
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Signed-off-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ufs: ufshpb: Remove enum initialization value
Bean Huo [Thu, 5 May 2022 13:47:03 +0000 (15:47 +0200)]
scsi: ufs: ufshpb: Remove enum initialization value

If the first enumerator has no initializer, the value of the corresponding
constant is zero.

Link: https://lore.kernel.org/r/20220505134707.35929-3-huobean@gmail.com
Reviewed-by: Keoseong Park <keosung.park@samsung.com>
Signed-off-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ufs: ufshpb: Merge ufshpb_reset() and ufshpb_reset_host()
Bean Huo [Thu, 5 May 2022 13:47:02 +0000 (15:47 +0200)]
scsi: ufs: ufshpb: Merge ufshpb_reset() and ufshpb_reset_host()

There is no functional change in this patch, just merge ufshpb_reset() and
ufshpb_reset_host() into one function ufshpb_toggle_state().

Link: https://lore.kernel.org/r/20220505134707.35929-2-huobean@gmail.com
Reviewed-by: Keoseong Park <keosung.park@samsung.com>
Signed-off-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM
Manivannan Sadhasivam [Wed, 4 May 2022 08:42:12 +0000 (14:12 +0530)]
scsi: ufs: qcom: Enable RPM_AUTOSUSPEND for runtime PM

In order to allow the block devices to enter autosuspend mode during
runtime, thereby allowing the ufshcd host driver to also runtime suspend,
let's make use of the RPM_AUTOSUSPEND flag.

Without this flag, userspace needs to enable the autosuspend feature of
the block devices through sysfs.

Link: https://lore.kernel.org/r/20220504084212.11605-6-manivannan.sadhasivam@linaro.org
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ufs: core: Remove redundant wmb() in ufshcd_send_command()
Manivannan Sadhasivam [Wed, 4 May 2022 08:42:11 +0000 (14:12 +0530)]
scsi: ufs: core: Remove redundant wmb() in ufshcd_send_command()

The wmb() inside ufshcd_send_command() is added to make sure that the
doorbell is committed immediately. This leads to couple of expectations:

 1. The doorbell write should complete before the function return.

 2. The doorbell write should not cross the function boundary.

2nd expectation is fullfilled by the Linux memory model as there is a
guarantee that the critical section won't cross the unlock (release)
operation.

1st expectation is not really needed here as there is no following read/
write that depends on the doorbell to be complete implicitly. Even if the
doorbell write is in a CPUs Write Buffer (WB), wmb() won't flush it. And
there is no real need of a WB flush here as well.

So let's get rid of the wmb() that seems redundant.

Link: https://lore.kernel.org/r/20220504084212.11605-5-manivannan.sadhasivam@linaro.org
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Acked-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled
Manivannan Sadhasivam [Wed, 4 May 2022 08:42:10 +0000 (14:12 +0530)]
scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled

In ufs_qcom_dev_ref_clk_ctrl(), it was noted that the ref_clk needs to be
stable for at least 1us. Even though there is wmb() to make sure the write
gets "completed", there is no guarantee that the write actually reached the
UFS device. There is a good chance that the write could be stored in a
Write Buffer (WB). In that case, even though the CPU waits for 1us, the
ref_clk might not be stable for that period.

So lets do a readl() to make sure that the previous write has reached the
UFS device before udelay().

Also, the wmb() after writel_relaxed() is not really needed. Both writel()
and readl() are ordered on all architectures and the CPU won't speculate
instructions after readl() due to the in-built control dependency with read
value on weakly ordered architectures. So it can be safely removed.

Link: https://lore.kernel.org/r/20220504084212.11605-4-manivannan.sadhasivam@linaro.org
Fixes: f06fcc7155dc ("scsi: ufs-qcom: add QUniPro hardware support and power optimizations")
Cc: stable@vger.kernel.org
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ufs: qcom: Simplify handling of devm_phy_get()
Manivannan Sadhasivam [Wed, 4 May 2022 08:42:09 +0000 (14:12 +0530)]
scsi: ufs: qcom: Simplify handling of devm_phy_get()

There is no need to call devm_phy_get() if ACPI is used, so skip it.  The
host->generic_phy pointer should already be NULL due to the kzalloc(), so
no need to set it NULL again.

While at it, also remove the comment that has no relationship with
devm_phy_get().

Link: https://lore.kernel.org/r/20220504084212.11605-3-manivannan.sadhasivam@linaro.org
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Reviewed-by: Andrew Halaney <ahalaney@redhat.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ufs: qcom: Fix acquiring the optional reset control line
Manivannan Sadhasivam [Wed, 4 May 2022 08:42:08 +0000 (14:12 +0530)]
scsi: ufs: qcom: Fix acquiring the optional reset control line

On Qcom UFS platforms, the reset control line seems to be optional (for
SoCs like MSM8996 and probably for others too). The current logic tries to
mimic the devm_reset_control_get_optional() API but it also continues the
probe if there is an error with the declared reset line in DT/ACPI.

In an ideal case, if the reset line is not declared in DT/ACPI, the probe
should continue. But if there is problem in acquiring the declared reset
line (like EPROBE_DEFER) it should fail and return the appropriate error
code.

Link: https://lore.kernel.org/r/20220504084212.11605-2-manivannan.sadhasivam@linaro.org
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Reviewed-by: Andrew Halaney <ahalaney@redhat.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: hisi_sas: Undo RPM resume for failed notify phy event for v3 HW
Xiang Chen [Fri, 6 May 2022 12:25:39 +0000 (20:25 +0800)]
scsi: hisi_sas: Undo RPM resume for failed notify phy event for v3 HW

If we fail to notify the phy up event then undo the RPM resume, as the phy
up notify event handling pairs with that RPM resume.

Link: https://lore.kernel.org/r/1651839939-101188-1-git-send-email-john.garry@huawei.com
Reported-by: Yihang Li <liyihang6@hisilicon.com>
Tested-by: Yihang Li <liyihang6@hisilicon.com>
Signed-off-by: Xiang Chen <chenxiang66@hisilicon.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Update driver version to 8.0.0.69.0
Sumit Saxena [Fri, 29 Apr 2022 21:16:41 +0000 (17:16 -0400)]
scsi: mpi3mr: Update driver version to 8.0.0.69.0

Link: https://lore.kernel.org/r/20220429211641.642010-9-sumit.saxena@broadcom.com
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Add support for NVMe passthrough
Sumit Saxena [Fri, 29 Apr 2022 21:16:40 +0000 (17:16 -0400)]
scsi: mpi3mr: Add support for NVMe passthrough

Add support for management applications to send an MPI3 Encapsulated NVMe
passthru command to the NVMe devices attached to an Avenger controller.
Since the NVMe drives are exposed as SCSI devices by the controller, the
standard NVMe applications cannot be used to interact with the drives and
the command sets supported are also limited by the controller firmware.
Special handling is required for MPI3 Encapsulated NVMe passthru commands
for PRP/SGL setup in the commands.

Link: https://lore.kernel.org/r/20220429211641.642010-8-sumit.saxena@broadcom.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Expose adapter state to sysfs
Sumit Saxena [Fri, 29 Apr 2022 21:16:39 +0000 (17:16 -0400)]
scsi: mpi3mr: Expose adapter state to sysfs

Link: https://lore.kernel.org/r/20220429211641.642010-7-sumit.saxena@broadcom.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Add support for PEL commands
Sumit Saxena [Fri, 29 Apr 2022 21:16:38 +0000 (17:16 -0400)]
scsi: mpi3mr: Add support for PEL commands

Implement driver support for management applications to enable persistent
event log (PEL) notifications. Upon receipt of events, the driver will
increment a sysfs variable named event_counter. The management application
will poll for event_counter value changes and signal the application about
events.

Link: https://lore.kernel.org/r/20220429211641.642010-6-sumit.saxena@broadcom.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Add support for MPT commands
Sumit Saxena [Fri, 29 Apr 2022 21:16:37 +0000 (17:16 -0400)]
scsi: mpi3mr: Add support for MPT commands

There are certain management commands which require firmware intervention.
These commands are termed MPT commands. Add support for them.

Link: https://lore.kernel.org/r/20220429211641.642010-5-sumit.saxena@broadcom.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Move data structures/definitions from MPI headers to uapi header
Sumit Saxena [Fri, 29 Apr 2022 21:16:36 +0000 (17:16 -0400)]
scsi: mpi3mr: Move data structures/definitions from MPI headers to uapi header

This patch moves the data structures/definitions which are used by
userspace applications from MPI headers to uapi/scsi/scsi_bsg_mpi3mr.h

Link: https://lore.kernel.org/r/20220429211641.642010-4-sumit.saxena@broadcom.com
Reported by: Stephen Rothwell <sfr@canb.auug.org.au>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Add support for driver commands
Sumit Saxena [Fri, 29 Apr 2022 21:16:35 +0000 (17:16 -0400)]
scsi: mpi3mr: Add support for driver commands

There are certain bsg commands which need to be completed by the driver
without involving firmware. These requests are termed driver commands. Add
support for these.

Link: https://lore.kernel.org/r/20220429211641.642010-3-sumit.saxena@broadcom.com
Reported by: Stephen Rothwell <sfr@canb.auug.org.au>
Reported-by: kernel test robot <lkp@intel.com>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpi3mr: Add bsg device support
Sumit Saxena [Fri, 29 Apr 2022 21:16:34 +0000 (17:16 -0400)]
scsi: mpi3mr: Add bsg device support

Create bsg device per controller for controller management purposes.

bsg device nodes will be named /dev/bsg/mpi3mrctl0, /dev/bsg/mpi3mrctl1,
etc.

Link: https://lore.kernel.org/r/20220429211641.642010-2-sumit.saxena@broadcom.com
Reported-by: kernel test robot <lkp@intel.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: sr: Add memory allocation failure handling for get_capabilities()
Enze Li [Wed, 27 Apr 2022 02:56:47 +0000 (10:56 +0800)]
scsi: sr: Add memory allocation failure handling for get_capabilities()

The function get_capabilities() has the possibility of failing to allocate
the transfer buffer but it does not currently handle this. This may lead to
exceptions when accessing the buffer.

Add error handling when memory allocation fails.

Link: https://lore.kernel.org/r/20220427025647.298358-1-lienze@kylinos.cn
Signed-off-by: Enze Li <lienze@kylinos.cn>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: target: tcmu: Fix possible data corruption
Xiaoguang Wang [Thu, 21 Apr 2022 02:37:35 +0000 (10:37 +0800)]
scsi: target: tcmu: Fix possible data corruption

When tcmu_vma_fault() gets a page successfully, before the current context
completes page fault procedure, find_free_blocks() may run and call
unmap_mapping_range() to unmap the page. Assume that when
find_free_blocks() initially completes and the previous page fault
procedure starts to run again and completes, then one truncated page has
been mapped to userspace. But note that tcmu_vma_fault() has gotten a
refcount for the page so any other subsystem won't be able to use the page
unless the userspace address is unmapped later.

If another command subsequently runs and needs to extend dbi_thresh it may
reuse the corresponding slot for the previous page in data_bitmap. Then
though we'll allocate new page for this slot in data_area, no page fault
will happen because we have a valid map and the real request's data will be
lost.

Filesystem implementations will also run into this issue but they usually
lock the page when vm_operations_struct->fault gets a page and unlock the
page after finish_fault() completes. For truncate filesystems lock pages in
truncate_inode_pages() to protect against racing wrt. page faults.

To fix this possible data corruption scenario we can apply a method similar
to the filesystems.  For pages that are to be freed, tcmu_blocks_release()
locks and unlocks. Make tcmu_vma_fault() also lock found page under
cmdr_lock. At the same time, since tcmu_vma_fault() gets an extra page
refcount, tcmu_blocks_release() won't free pages if pages are in page fault
procedure, which means it is safe to call tcmu_blocks_release() before
unmap_mapping_range().

With these changes tcmu_blocks_release() will wait for all page faults to
be completed before calling unmap_mapping_range(). And later, if
unmap_mapping_range() is called, it will ensure stale mappings are removed.

Link: https://lore.kernel.org/r/20220421023735.9018-1-xiaoguang.wang@linux.alibaba.com
Reviewed-by: Bodo Stroesser <bostroesser@gmail.com>
Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Remove redundant lpfc_sli_prep_wqe() call
James Smart [Wed, 27 Apr 2022 22:22:23 +0000 (15:22 -0700)]
scsi: lpfc: Remove redundant lpfc_sli_prep_wqe() call

Prior patch added a call to lpfc_sli_prep_wqe() prior to
lpfc_sli_issue_iocb().  This call should not have been added as prep_wqe is
called within the issue_iocb routine. So it's called twice now.

Remove the redundant prep call.

Link: https://lore.kernel.org/r/20220427222223.57920-1-jsmart2021@gmail.com
Fixes: 31a59f75702f ("scsi: lpfc: SLI path split: Refactor Abort paths")
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Fix additional reference counting in lpfc_bsg_rport_els()
James Smart [Wed, 27 Apr 2022 22:21:58 +0000 (15:21 -0700)]
scsi: lpfc: Fix additional reference counting in lpfc_bsg_rport_els()

Code inspection has found an additional reference is taken in
lpfc_bsg_rport_els(). Results in the ndlp not being freed thus is leaked.

Fix by removing the redundant refcount taken before WQE submission.

Link: https://lore.kernel.org/r/20220427222158.57867-1-jsmart2021@gmail.com
Co-developed-by: Nigel Kirkland <nigel.kirkland@broadcom.com>
Signed-off-by: Nigel Kirkland <nigel.kirkland@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: sd: Reorganize DIF/DIX code to avoid calling revalidate twice
Martin K. Petersen [Wed, 2 Mar 2022 05:35:58 +0000 (00:35 -0500)]
scsi: sd: Reorganize DIF/DIX code to avoid calling revalidate twice

During device discovery we ended up calling revalidate twice and thus
requested the same parameters multiple times. This was originally necessary
due to the request_queue and gendisk needing to be instantiated to
configure the block integrity profile.

Since this dependency no longer exists, reorganize the integrity probing
code so it can be run once at the end of discovery and drop the superfluous
revalidate call. Postponing the registration step involves splitting
sd_read_protection() into two functions, one to read the device protection
type and one to configure the mode of operation.

As part of this cleanup, make the printing code a bit less verbose.

Link: https://lore.kernel.org/r/20220302053559.32147-14-martin.petersen@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: sd: Optimal I/O size should be a multiple of reported granularity
Martin K. Petersen [Wed, 2 Mar 2022 05:35:53 +0000 (00:35 -0500)]
scsi: sd: Optimal I/O size should be a multiple of reported granularity

Commit a83da8a4509d ("scsi: sd: Optimal I/O size should be a multiple of
physical block size") validated the reported optimal I/O size against the
physical block size to overcome problems with devices reporting nonsensical
transfer sizes.

However, some devices claim conformity to older SCSI versions that predate
the physical block size being reported. Other devices do not report a
physical block size at all. We need to be able to validate the optimal I/O
size on those devices as well.

Many devices report an OPTIMAL TRANSFER LENGTH GRANULARITY in the same VPD
page as the OPTIMAL TRANSFER LENGTH. Use this value to validate the optimal
I/O size. Also check that the reported granularity is a multiple of the
physical block size, if supported.

Link: https://lore.kernel.org/r/33fb522e-4f61-1b76-914f-c9e6a3553c9b@gmail.com
Link: https://lore.kernel.org/r/20220302053559.32147-9-martin.petersen@oracle.com
Reported-by: Bernhard Sulzer <micraft.b@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: sd: Switch to using scsi_device VPD pages
Martin K. Petersen [Wed, 2 Mar 2022 05:35:52 +0000 (00:35 -0500)]
scsi: sd: Switch to using scsi_device VPD pages

Use the VPD pages already provided by the SCSI midlayer. No need to request
them individually in the SCSI disk driver.

Link: https://lore.kernel.org/r/20220302053559.32147-8-martin.petersen@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: sd: Use cached ATA Information VPD page
Martin K. Petersen [Wed, 2 Mar 2022 05:35:51 +0000 (00:35 -0500)]
scsi: sd: Use cached ATA Information VPD page

Since the ATA Information VPD is now cached at device discovery time it is
no longer necessary to request this page when we configure WRITE SAME.
Instead use the cached information to determine if this disk sits behind a
SCSI-ATA translation layer.

Link: https://lore.kernel.org/r/20220302053559.32147-7-martin.petersen@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: core: Do not truncate INQUIRY data on modern devices
Martin K. Petersen [Wed, 2 Mar 2022 05:35:48 +0000 (00:35 -0500)]
scsi: core: Do not truncate INQUIRY data on modern devices

Low-level device drivers have had the ability to limit the size of an
INQUIRY for many years. This made sense for a wide variety of legacy
devices. However, we are unnecessarily truncating the INQUIRY response for
many modern devices. This prevents us from consulting fields beyond the
first 36 bytes.

If a device reports that it supports a larger INQUIRY response, and the
device also reports that it implements SPC-4 or newer, allow the larger
INQUIRY to proceed.

Link: https://lore.kernel.org/r/20220302053559.32147-4-martin.petersen@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: core: Cache VPD pages b0, b1, b2
Martin K. Petersen [Wed, 2 Mar 2022 05:35:50 +0000 (00:35 -0500)]
scsi: core: Cache VPD pages b0, b1, b2

The SCSI disk driver consults VPD pages b0 (Block Limits), b1 (Block Device
Characteristics), and b2 (Logical Block Provisioning). Instead of having
sd.c request these pages every revalidate cycle, cache them along with the
other commonly used VPDs.

Link: https://lore.kernel.org/r/20220302053559.32147-6-martin.petersen@oracle.com
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: core: Pick suitable allocation length in scsi_report_opcode()
Martin K. Petersen [Wed, 2 Mar 2022 05:35:49 +0000 (00:35 -0500)]
scsi: core: Pick suitable allocation length in scsi_report_opcode()

Some devices hang when a buffer size larger than expected is passed in the
ALLOCATION LENGTH field. For REPORT SUPPORTED OPERATION CODES we currently
only request a single command descriptor at a time and therefore the actual
size of the command is known ahead of time. Limit the ALLOCATION LENGTH to
the header size plus the command length of the opcode we are asking about.

Link: https://lore.kernel.org/r/20220302053559.32147-5-martin.petersen@oracle.com
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: core: Query VPD size before getting full page
Martin K. Petersen [Wed, 2 Mar 2022 05:35:47 +0000 (00:35 -0500)]
scsi: core: Query VPD size before getting full page

We currently default to 255 bytes when fetching VPD pages during discovery.
However, we have had a few devices that are known to wedge if the requested
buffer exceeds a certain size. See commit af73623f5f10 ("[SCSI] sd: Reduce
buffer size for vpd request") which works around one example of this
problem in the SCSI disk driver.

With commit d188b0675b21 ("scsi: core: Add sysfs attributes for VPD pages
0h and 89h") we now risk triggering the same issue in the generic midlayer
code.

The problem with the ATA VPD page in particular is that the SCSI portion of
the page is trailed by 512 bytes of verbatim ATA Identify Device
information.  However, not all controllers actually provide the additional
512 bytes and will lock up if one asks for more than the 64 bytes
containing the SCSI protocol fields.

Instead of picking a new, somewhat arbitrary, number of bytes for the VPD
buffer size, start fetching the 4-byte header for each page. The header
contains the size of the page as far as the device is concerned. We can use
the reported size to specify the correct allocation length when
subsequently fetching the full page.

The header validation is done by a new helper function scsi_get_vpd_size()
and both scsi_get_vpd_page() and scsi_get_vpd_buf() now rely on this to
query the page size.

In addition, scsi_get_vpd_page() is simplified to mirror the logic in
scsi_get_vpd_page(). This involves removing the Supported VPD Pages lookup
prior to attempting to query a page. There does not appear any evidence,
even in the oldest SCSI specs, that this step is required. We already rely
on scsi_get_vpd_page() throughout the stack and this function never
consulted the Supported VPD Pages. Since this has not caused any problems
it should be safe to remove the precondition from scsi_get_vpd_page().

Instrumented runs also revealed that the Supported VPD Pages lookup had
little effect since the device page index often was larger than the
supplied buffer size. As a result, inquiries frequently bypassed the index
check and went through the "If we ran off the end of the buffer, give us
the benefit of the doubt" code path which assumed the page was present
despite not being listed. The revised code takes both the page size
reported by the device as well as the size of the buffer provided by the
scsi_get_vpd_page() caller into account.

Link: https://lore.kernel.org/r/20220302053559.32147-3-martin.petersen@oracle.com
Fixes: d188b0675b21 ("scsi: core: Add sysfs attributes for VPD pages 0h and 89h")
Reported-by: Maciej W. Rozycki <macro@orcam.me.uk>
Tested-by: Maciej W. Rozycki <macro@orcam.me.uk>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: mpt3sas: Use cached ATA Information VPD page
Martin K. Petersen [Wed, 2 Mar 2022 05:35:46 +0000 (00:35 -0500)]
scsi: mpt3sas: Use cached ATA Information VPD page

We now cache VPD page 0x89 (ATA Information) so there is no need to request
it from the hardware. Make mpt3sas use the cached page.

Link: https://lore.kernel.org/r/20220302053559.32147-2-martin.petersen@oracle.com
Cc: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Fix resource leak in lpfc_sli4_send_seq_to_ulp()
James Smart [Tue, 26 Apr 2022 18:14:19 +0000 (11:14 -0700)]
scsi: lpfc: Fix resource leak in lpfc_sli4_send_seq_to_ulp()

If no handler is found in lpfc_complete_unsol_iocb() to match the rctl of a
received frame, the frame is dropped and resources are leaked.

Fix by returning resources when discarding an unhandled frame type.  Update
lpfc_fc_frame_check() handling of NOP basic link service.

Link: https://lore.kernel.org/r/20220426181419.9154-1-jsmart2021@gmail.com
Co-developed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: lpfc: Remove unnecessary null ndlp check in lpfc_sli_prep_wqe()
James Smart [Tue, 26 Apr 2022 18:13:15 +0000 (11:13 -0700)]
scsi: lpfc: Remove unnecessary null ndlp check in lpfc_sli_prep_wqe()

Smatch had the following warning:

drivers/scsi/lpfc/lpfc_sli.c:22305 lpfc_sli_prep_wqe() error: we previously assumed 'ndlp' could be null (see line 22298)

Remove the unnecessary null check.

Link: https://lore.kernel.org/r/20220426181315.8990-1-jsmart2021@gmail.com
Fixes: d51cf5bd926c ("scsi: lpfc: Fix field overload in lpfc_iocbq data structure")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: ufs: Use pm_runtime_resume_and_get() instead of pm_runtime_get_sync()
Minghao Chi [Wed, 20 Apr 2022 09:03:52 +0000 (09:03 +0000)]
scsi: ufs: Use pm_runtime_resume_and_get() instead of pm_runtime_get_sync()

Using pm_runtime_resume_and_get() to replace pm_runtime_get_sync() and
pm_runtime_put_noidle(). This change is just to simplify the code, no
actual functional changes.

Link: https://lore.kernel.org/r/20220420090353.2588804-1-chi.minghao@zte.com.cn
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: megaraid: Fix error check return value of register_chrdev()
Lv Ruyi [Mon, 18 Apr 2022 10:57:55 +0000 (10:57 +0000)]
scsi: megaraid: Fix error check return value of register_chrdev()

If major equals 0, register_chrdev() returns an error code when it fails.
This function dynamically allocates a major and returns its number on
success, so we should use "< 0" to check it instead of "!".

Link: https://lore.kernel.org/r/20220418105755.2558828-1-lv.ruyi@zte.com.cn
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2 years agoscsi: qla2xxx: edif: Remove unneeded variable
Guo Zhengkui [Tue, 26 Apr 2022 07:43:34 +0000 (15:43 +0800)]
scsi: qla2xxx: edif: Remove unneeded variable

Fix the following coccicheck warning:

drivers/scsi/qla2xxx/qla_edif.c:660:11-15: Unneeded variable: "rval".

Return "0" on line 761.

Link: https://lore.kernel.org/r/20220426074334.9281-1-guozhengkui@vivo.com
Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>