History log of /linux-master/drivers/scsi/mpt3sas/mpt3sas_ctl.c
Revision Date Author Comments
# c0767560 28-Dec-2023 Ranjan Kumar <ranjan.kumar@broadcom.com>

scsi: mpt3sas: Reload SBR without rebooting HBA

Add a new IOCTL command MPT3ENABLEDIAGSBRRELOAD. As a part of firmware
update operation, applications use this IOCTL command to set the SBR reload
bit in the Host Diagnostic register. This permits HBA firmware to be
updated without powercycling the system.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202312280909.MZyhxwBL-lkp@intel.com/
Closes: https://lore.kernel.org/oe-kbuild-all/202312281141.jDyPezRn-lkp@intel.com/
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
Link: https://lore.kernel.org/r/20231228114810.11923-2-ranjan.kumar@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 6a965ee1 19-Oct-2023 Tomas Henzl <thenzl@redhat.com>

scsi: mpt3sas: Suppress a warning in debug kernel

The mpt3sas_ctl_exit() should be called after communication with the
controller stops but currently it may cause false warnings about not
released memory. Fix this by letting mpt3sas_ctl_exit() handle misc driver
release per driver and release DMA in mpt3sas_ctl_release() per ioc.

Signed-off-by: Tomas Henzl <thenzl@redhat.com>
Link: https://lore.kernel.org/r/20231019153706.7967-1-thenzl@redhat.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 1eeedfad 03-Jan-2023 Paul Menzel <pmenzel@molgen.mpg.de>

scsi: mpt3sas: Demote log level for trace buffer allocation to info

Linux logs the error below:

$ dmesg --level=err | grep mpt
[ 7.647675] mpt3sas_cm0: Trace buffer memory 2048 KB allocated

This state does not denote an error condition (and also no warning), so
demote the level from error to info.

Cc: it+linux-scsi@molgen.mpg.de
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
Link: https://lore.kernel.org/r/20230103150438.45922-1-pmenzel@molgen.mpg.de
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 463e683b 25-Aug-2022 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: Fix trace buffer registration failed

The ExtendedType field was set to 1 in the diag buffer register command and
hence MPT Endpoint firmware is failing the request with Invalid Field
IOCStatus.

memset the request frame to zero before framing the diag buffer register
command.

Link: https://lore.kernel.org/r/20220825075457.16422-3-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# f45fadde 05-Aug-2022 Bradley Grove <bgrove@attotech.com>

scsi: mpt3sas: Disable MPI2_FUNCTION_FW_DOWNLOAD for ATTO devices

Disable firmware download for ATTO devices where it is not supported.

Link: https://lore.kernel.org/r/20220805174609.14830-2-bgrove@attotech.com
Co-developed-by: Rob Crispo <rcrispo@attotech.com>
Signed-off-by: Rob Crispo <rcrispo@attotech.com>
Signed-off-by: Bradley Grove <bgrove@attotech.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# dceaef94 07-Mar-2022 Damien Le Moal <damien.lemoal@opensource.wdc.com>

scsi: mpt3sas: Fix _ctl_set_task_mid() TaskMID check

The TaskMID field of struct Mpi2SCSITaskManagementRequest_t is a 16-bit
little endian value. Fix the search loop in _ctl_set_task_mid() to add a
cpu_to_le16() conversion before checking the value of TaskMID to avoid
sparse warnings. While at it, simplify the search loop code to remove an
unnecessarily complicated if condition.

Link: https://lore.kernel.org/r/20220307234854.148145-2-damien.lemoal@opensource.wdc.com
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 9211faa3 26-Dec-2021 Suganath Prabu S <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Update persistent trigger pages from sysfs interface

Store sysfs-provided trigger values into the corresponding persistent
trigger pages. Otherwise trigger entries are not persistent across system
reboots.

Link: https://lore.kernel.org/r/20211227053055.289537-1-suganath-prabu.subramani@broadcom.com
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 0ae8f478 19-Oct-2021 Jiapeng Chong <jiapeng.chong@linux.alibaba.com>

scsi: mpt3sas: Make mpt3sas_dev_attrs static

This symbol is not used outside of mpt3sas_ctl.c, mark it static.

Fixes the following sparse warning:

drivers/scsi/mpt3sas/mpt3sas_ctl.c:3988:18: warning: symbol
'mpt3sas_dev_attrs' was not declared. Should it be static?

Link: https://lore.kernel.org/r/1634639239-2892-1-git-send-email-jiapeng.chong@linux.alibaba.com
Fixes: 1bb3ca27d2ca ("scsi: mpt3sas: Switch to attribute groups")
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 1bb3ca27 12-Oct-2021 Bart Van Assche <bvanassche@acm.org>

scsi: mpt3sas: Switch to attribute groups

struct device supports attribute groups directly but does not support
struct device_attribute directly. Hence switch to attribute groups.

Link: https://lore.kernel.org/r/20211012233558.4066756-30-bvanassche@acm.org
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 04c260bd 02-Sep-2021 Colin Ian King <colin.king@canonical.com>

scsi: mpt3sas: Clean up some inconsistent indenting

There are a couple of statements where the indentation is not correct,
clean these up. Remove a redundant break statement.

Link: https://lore.kernel.org/r/20210902224215.57286-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>


# 4758fd91 06-Aug-2021 Damien Le Moal <damien.lemoal@wdc.com>

scsi: mpt3sas: Introduce sas_ncq_prio_supported sysfs sttribute

Similarly to AHCI, introduce the device sysfs attribute
sas_ncq_prio_supported to advertise if a SATA device supports the NCQ
priority feature. Without this new attribute, the user can only discover if
a SATA device supports NCQ priority by trying to enable the feature use
with the sas_ncq_prio_enable sysfs device attribute, which fails when the
device does not support high prioity commands.

Link: https://lore.kernel.org/r/20210807041859.579409-11-damien.lemoal@wdc.com
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 787f2448 08-Aug-2021 Suganath Prabu S <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Use firmware recommended queue depth

Currently, the mpt3sas driver sets the default queue depth based on the
physical interface of the attached device:

- SAS : 254
- SATA: 32
- NVMe: 128

The IOC firmware provides a recommended queue depth for each device through
SAS IO Unit Page1 for SAS/SATA and PCIe IO Unit Page 1 for NVMe devices.

If the host sets the queue depth greater than the firmware recommended
value, then the IOC places the I/Os above the recommended queue depth in an
internal pending queue. This consumes outstanding host-credit/resources,
thereby leading to potential starvation of other devices.

To avoid this, use the device depth recommended by the IOC firmware.

Link: https://lore.kernel.org/r/20210809072639.21228-2-suganath-prabu.subramani@broadcom.com
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 16660db3 01-Apr-2021 Gustavo A. R. Silva <gustavoars@kernel.org>

scsi: mpt3sas: Fix out-of-bounds warnings in _ctl_addnl_diag_query

Fix the following out-of-bounds warnings by embedding existing struct
htb_rel_query into struct mpt3_addnl_diag_query, instead of duplicating its
members:

include/linux/fortify-string.h:20:29: warning: '__builtin_memcpy' offset [19, 32] from the object at 'karg' is out of the bounds of referenced subobject 'buffer_rel_condition' with type 'short unsigned int' at offset 16 [-Warray-bounds]
include/linux/fortify-string.h:22:29: warning: '__builtin_memset' offset [19, 32] from the object at 'karg' is out of the bounds of referenced subobject 'buffer_rel_condition' with type 'short unsigned int' at offset 16 [-Warray-bounds]

The problem is that the original code is trying to copy data into a bunch
of struct members adjacent to each other in a single call to memcpy(). All
those members are exactly the same contained in struct htb_rel_query, so
instead of duplicating them into struct mpt3_addnl_diag_query, replace them
with new member rel_query of type struct htb_rel_query. So, now that this
new object is introduced, memcpy() doesn't overrun the length of
&karg.buffer_rel_condition, because the address of the new struct object
_rel_query_ is used as destination, instead. The same issue is present when
calling memset(), and it is fixed with this same approach.

Below is a comparison of struct mpt3_addnl_diag_query, before and after
this change (the size and cachelines remain the same):

$ pahole -C mpt3_addnl_diag_query drivers/scsi/mpt3sas/mpt3sas_ctl.o
struct mpt3_addnl_diag_query {
struct mpt3_ioctl_header hdr; /* 0 12 */
uint32_t unique_id; /* 12 4 */
uint16_t buffer_rel_condition; /* 16 2 */
uint16_t reserved1; /* 18 2 */
uint32_t trigger_type; /* 20 4 */
uint32_t trigger_info_dwords[2]; /* 24 8 */
uint32_t reserved2[2]; /* 32 8 */

/* size: 40, cachelines: 1, members: 7 */
/* last cacheline: 40 bytes */
};

$ pahole -C mpt3_addnl_diag_query drivers/scsi/mpt3sas/mpt3sas_ctl.o
struct mpt3_addnl_diag_query {
struct mpt3_ioctl_header hdr; /* 0 12 */
uint32_t unique_id; /* 12 4 */
struct htb_rel_query rel_query; /* 16 16 */
uint32_t reserved2[2]; /* 32 8 */

/* size: 40, cachelines: 1, members: 4 */
/* last cacheline: 40 bytes */
};

Also, this helps with the ongoing efforts to globally enable -Warray-bounds
and get us closer to being able to tighten the FORTIFY_SOURCE routines on
memcpy().

Link: https://github.com/KSPP/linux/issues/109
Link: https://lore.kernel.org/lkml/60659889.bJJILx2THu3hlpxW%25lkp@intel.com/
Link: https://lore.kernel.org/r/20210401162054.GA397186@embeddedor
Build-tested-by: kernel test robot <lkp@intel.com>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# a1c4d774 10-Mar-2021 Gustavo A. R. Silva <gustavoars@kernel.org>

scsi: mpt3sas: Replace unnecessary dynamic allocation with a static one

Dynamic memory allocation isn't actually needed and it can be replaced by
statically allocating memory for struct object io_unit_pg3 with 36
hardcoded entries for its GPIOVal array.

Also, this helps the with ongoing efforts to enable -Warray-bounds by
fixing the following warning:

drivers/scsi/mpt3sas/mpt3sas_ctl.c: In function ‘BRM_status_show’:
drivers/scsi/mpt3sas/mpt3sas_ctl.c:3257:63: warning: array subscript 24 is above array bounds of ‘U16[1]’ {aka ‘short unsigned int[1]’} [-Warray-bounds]
3257 | backup_rail_monitor_status = le16_to_cpu(io_unit_pg3->GPIOVal[24]);
./include/uapi/linux/byteorder/little_endian.h:36:51: note: in definition of macro ‘__le16_to_cpu’
36 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
| ^
drivers/scsi/mpt3sas/mpt3sas_ctl.c:3257:31: note: in expansion of macro ‘le16_to_cpu’
3257 | backup_rail_monitor_status = le16_to_cpu(io_unit_pg3->GPIOVal[24]);

Link: https://github.com/KSPP/linux/issues/109
Link: https://lore.kernel.org/lkml/202103101058.16ED27BE3@keescook/
Link: https://lore.kernel.org/r/20210310235951.GA108661@embeddedor
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 782a1ab3 12-Mar-2021 Lee Jones <lee.jones@linaro.org>

scsi: mpt3sas: Fix some kernel-doc misnaming issues

Fixes the following W=1 kernel build warning(s):

drivers/scsi/mpt3sas/mpt3sas_ctl.c:463: warning: expecting prototype for mpt3sas_ctl_reset_handler(). Prototype was for mpt3sas_ctl_pre_reset_handler() instead
drivers/scsi/mpt3sas/mpt3sas_ctl.c:495: warning: expecting prototype for mpt3sas_ctl_reset_handler(). Prototype was for mpt3sas_ctl_clear_outstanding_ioctls() instead
drivers/scsi/mpt3sas/mpt3sas_ctl.c:512: warning: expecting prototype for mpt3sas_ctl_reset_handler(). Prototype was for mpt3sas_ctl_reset_done_handler() instead
drivers/scsi/mpt3sas/mpt3sas_ctl.c:2771: warning: expecting prototype for _ ctl_ioctl_compat(). Prototype was for _ctl_ioctl_compat() instead
drivers/scsi/mpt3sas/mpt3sas_ctl.c:2789: warning: expecting prototype for _ ctl_mpt2_ioctl_compat(). Prototype was for _ctl_mpt2_ioctl_compat() instead
drivers/scsi/mpt3sas/mpt3sas_ctl.c:3061: warning: expecting prototype for sas_address_show(). Prototype was for host_sas_address_show() instead
drivers/scsi/mpt3sas/mpt3sas_ctl.c:3682: warning: expecting prototype for diag_trigger_scsi_show(). Prototype was for diag_trigger_mpi_show() instead
drivers/scsi/mpt3sas/mpt3sas_ctl.c:3941: warning: expecting prototype for sas_ncq_io_prio_show(). Prototype was for sas_ncq_prio_enable_show() instead

Link: https://lore.kernel.org/r/20210312094738.2207817-10-lee.jones@linaro.org
Cc: Sathya Prakash <sathya.prakash@broadcom.com>
Cc: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Cc: Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: MPT-FusionLinux.pdl@avagotech.com
Cc: MPT-FusionLinux.pdl@broadcom.com
Cc: linux-scsi@vger.kernel.org
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 688c1a0a 03-Feb-2021 Suganath Prabu S <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Additional diagnostic buffer query interface

When a host trace buffer is released, applications never know for what
reason the buffer is released. Add a new IOCTL MPT3ADDNLDIAGQUERY to
provide the trigger information due to which the diag buffer is released.

Link: https://lore.kernel.org/r/20210204033724.1345-2-suganath-prabu.subramani@broadcom.com
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 42f68703 25-Nov-2020 Suganath Prabu S <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Fix ioctl timeout

Commit c1a6c5ac4278 ("scsi: mpt3sas: For NVME device, issue a protocol
level reset") modified the ioctl path 'timeout' variable type to u8 from
unsigned long, limiting the maximum timeout value that the driver can
support to 255 seconds.

If the management application is requesting a higher value the resulting
timeout will be zero. The operation times out immediately and the ioctl
request fails.

Change datatype back to unsigned long.

Link: https://lore.kernel.org/r/20201125094838.4340-1-suganath-prabu.subramani@broadcom.com
Fixes: c1a6c5ac4278 ("scsi: mpt3sas: For NVME device, issue a protocol level reset")
Cc: <stable@vger.kernel.org> #v4.18+
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 324c122f 27-Oct-2020 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: Add module parameter multipath_on_hba

Add module parameter multipath_on_hba to enable/disable multi-port path
topology support. By default this feature is enabled on SAS3.5 HBA device
and disabled on SAS3 &SAS2.5 HBA devices.

When this feature is disabled then driver uses a default
PhysicalPort(PortID) number i.e. 255 instead of the PhysicalPort number
provided by HBA firmware.

Link: https://lore.kernel.org/r/20201027130847.9962-14-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# a5a20c4a 29-Jul-2020 Suraj Upadhyay <usuraj35@gmail.com>

scsi: mpt3sas: Remove pci-dma-compat wrapper API

The legacy API wrappers in include/linux/pci-dma-compat.h should go away as
they create unnecessary midlayering for include/linux/dma-mapping.h API.
Instead use dma-mapping.h API directly.

The patch has been generated with the coccinelle script below. Compile
tested.

@@@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL

@@@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE

@@@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE

@@@@
- PCI_DMA_NONE
+ DMA_NONE

@@ expression E1, E2, E3; @@
- pci_alloc_consistent(E1, E2, E3)
+ dma_alloc_coherent(&E1->dev, E2, E3, GFP_)

@@ expression E1, E2, E3; @@
- pci_zalloc_consistent(E1, E2, E3)
+ dma_alloc_coherent(&E1->dev, E2, E3, GFP_)

@@ expression E1, E2, E3, E4; @@
- pci_free_consistent(E1, E2, E3, E4)
+ dma_free_coherent(&E1->dev, E2, E3, E4)

@@ expression E1, E2, E3, E4; @@
- pci_map_single(E1, E2, E3, E4)
+ dma_map_single(&E1->dev, E2, E3, E4)

@@ expression E1, E2, E3, E4; @@
- pci_unmap_single(E1, E2, E3, E4)
+ dma_unmap_single(&E1->dev, E2, E3, E4)

@@ expression E1, E2, E3, E4, E5; @@
- pci_map_page(E1, E2, E3, E4, E5)
+ dma_map_page(&E1->dev, E2, E3, E4, E5)

@@ expression E1, E2, E3, E4; @@
- pci_unmap_page(E1, E2, E3, E4)
+ dma_unmap_page(&E1->dev, E2, E3, E4)

@@ expression E1, E2, E3, E4; @@
- pci_map_sg(E1, E2, E3, E4)
+ dma_map_sg(&E1->dev, E2, E3, E4)

@@ expression E1, E2, E3, E4; @@
- pci_unmap_sg(E1, E2, E3, E4)
+ dma_unmap_sg(&E1->dev, E2, E3, E4)

@@ expression E1, E2, E3, E4; @@
- pci_dma_sync_single_for_cpu(E1, E2, E3, E4)
+ dma_sync_single_for_cpu(&E1->dev, E2, E3, E4)

@@ expression E1, E2, E3, E4; @@
- pci_dma_sync_single_for_device(E1, E2, E3, E4)
+ dma_sync_single_for_device(&E1->dev, E2, E3, E4)

@@ expression E1, E2, E3, E4; @@
- pci_dma_sync_sg_for_cpu(E1, E2, E3, E4)
+ dma_sync_sg_for_cpu(&E1->dev, E2, E3, E4)

@@ expression E1, E2, E3, E4; @@
- pci_dma_sync_sg_for_device(E1, E2, E3, E4)
+ dma_sync_sg_for_device(&E1->dev, E2, E3, E4)

@@ expression E1, E2; @@
- pci_dma_mapping_error(E1, E2)
+ dma_mapping_error(&E1->dev, E2)

@@ expression E1, E2; @@
- pci_set_consistent_dma_mask(E1, E2)
+ dma_set_coherent_mask(&E1->dev, E2)

@@ expression E1, E2; @@
- pci_set_dma_mask(E1, E2)
+ dma_set_mask(&E1->dev, E2)

Link: https://lore.kernel.org/r/e825ac7108092cc8fa8d462dc702098ef10fc6a2.1596045683.git.usuraj35@gmail.com
Signed-off-by: Suraj Upadhyay <usuraj35@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# df561f66 23-Aug-2020 Gustavo A. R. Silva <gustavoars@kernel.org>

treewide: Use fallthrough pseudo-keyword

Replace the existing /* fall through */ comments and its variants with
the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary
fall-through markings when it is the case.

[1] https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>


# 521e9c0b 30-Jul-2020 Suganath Prabu S <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Add functions to check if any cmd is outstanding on Target and LUN

Add helper functions to check whether any SCSI command is outstanding on
particular Target, LUN device.

Also add function parameters 'channel', 'id' to function
mpt3sas_scsih_issue_tm().

Link: https://lore.kernel.org/r/1596096229-3341-6-git-send-email-suganath-prabu.subramani@broadcom.com
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 9133d27e 06-Jul-2020 Damien Le Moal <damien.lemoal@wdc.com>

scsi: mpt3sas: Fix kdoc comments format

Fix kdoc comments format to avoid compiler warnings when compiling with
W=1.

No functional changes.

Link: https://lore.kernel.org/r/20200706123358.452180-1-damien.lemoal@wdc.com
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 0fd18145 01-Jul-2020 Johannes Thumshirn <johannes.thumshirn@wdc.com>

scsi: mpt3sas: Fix error returns in BRM_status_show

BRM_status_show() has several error branches, but none of them record the
error in the error return.

Also while at it remove the manual mutex_unlock() of the pci_access_mutex
in case of an ongoing pci error recovery or host removal and jump to the
cleanup label instead.

Note: We can safely jump to out from here as io_unit_pg3 is initialized to
NULL and if it hasn't been allocated, kfree() skips the NULL pointer.

[mkp: compilation warning]

Link: https://lore.kernel.org/r/20200701131454.5255-1-johannes.thumshirn@wdc.com
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# cb551b8d 01-Jul-2020 Damien Le Moal <damien.lemoal@wdc.com>

scsi: mpt3sas: Fix unlock imbalance

In BRM_status_show(), if the condition "!ioc->is_warpdrive" tested on entry
to the function is true, a "goto out" is called. This results in unlocking
ioc->pci_access_mutex without this mutex lock being taken. This generates
the following splat:

[ 1148.539883] mpt3sas_cm2: BRM_status_show: BRM attribute is only for warpdrive
[ 1148.547184]
[ 1148.548708] =====================================
[ 1148.553501] WARNING: bad unlock balance detected!
[ 1148.558277] 5.8.0-rc3+ #827 Not tainted
[ 1148.562183] -------------------------------------
[ 1148.566959] cat/5008 is trying to release lock (&ioc->pci_access_mutex) at:
[ 1148.574035] [<ffffffffc070b7a3>] BRM_status_show+0xd3/0x100 [mpt3sas]
[ 1148.580574] but there are no more locks to release!
[ 1148.585524]
[ 1148.585524] other info that might help us debug this:
[ 1148.599624] 3 locks held by cat/5008:
[ 1148.607085] #0: ffff92aea3e392c0 (&p->lock){+.+.}-{3:3}, at: seq_read+0x34/0x480
[ 1148.618509] #1: ffff922ef14c4888 (&of->mutex){+.+.}-{3:3}, at: kernfs_seq_start+0x2a/0xb0
[ 1148.630729] #2: ffff92aedb5d7310 (kn->active#224){.+.+}-{0:0}, at: kernfs_seq_start+0x32/0xb0
[ 1148.643347]
[ 1148.643347] stack backtrace:
[ 1148.655259] CPU: 73 PID: 5008 Comm: cat Not tainted 5.8.0-rc3+ #827
[ 1148.665309] Hardware name: HGST H4060-S/S2600STB, BIOS SE5C620.86B.02.01.0008.031920191559 03/19/2019
[ 1148.678394] Call Trace:
[ 1148.684750] dump_stack+0x78/0xa0
[ 1148.691802] lock_release.cold+0x45/0x4a
[ 1148.699451] __mutex_unlock_slowpath+0x35/0x270
[ 1148.707675] BRM_status_show+0xd3/0x100 [mpt3sas]
[ 1148.716092] dev_attr_show+0x19/0x40
[ 1148.723664] sysfs_kf_seq_show+0x87/0x100
[ 1148.731193] seq_read+0xbc/0x480
[ 1148.737882] vfs_read+0xa0/0x160
[ 1148.744514] ksys_read+0x58/0xd0
[ 1148.751129] do_syscall_64+0x4c/0xa0
[ 1148.757941] entry_SYSCALL_64_after_hwframe+0x44/0xa9
[ 1148.766240] RIP: 0033:0x7f1230566542
[ 1148.772957] Code: Bad RIP value.
[ 1148.779206] RSP: 002b:00007ffeac1bcac8 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
[ 1148.790063] RAX: ffffffffffffffda RBX: 0000000000020000 RCX: 00007f1230566542
[ 1148.800284] RDX: 0000000000020000 RSI: 00007f1223460000 RDI: 0000000000000003
[ 1148.810474] RBP: 00007f1223460000 R08: 00007f122345f010 R09: 0000000000000000
[ 1148.820641] R10: 0000000000000022 R11: 0000000000000246 R12: 0000000000000000
[ 1148.830728] R13: 0000000000000003 R14: 0000000000020000 R15: 0000000000020000

Fix this by returning immediately instead of jumping to the out label.

Link: https://lore.kernel.org/r/20200701085254.51740-1-damien.lemoal@wdc.com
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Acked-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# c6bdb6a1 26-Dec-2019 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: Print function name in which cmd timed out

Print the function name in which MPT command got timed out. This will
facilitate debugging in which path corresponding MPT command got timeout in
first failure instance of log itself.

Link: https://lore.kernel.org/r/20191226111333.26131-9-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 5b061980 26-Dec-2019 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: Optimize mpt3sas driver logging

This improves mpt3sas driver default debug information collection and
allows for a higher percentage of issues being able to be resolved with a
first-time data capture. However, this improvement to balance the amount
of debug data captured with the performance of driver.

Enabled below print messages with out affecting the IO performance,

1. When task abort TM is received then print IO commands's timeout value
and how much time this command has been outstanding.

2. Whenever hard reset occurs then print from where this hard reset has
been issued.

3. Failure message should be displayed for failure scenarios without any
logging level.

4. Added a print after driver successfully register or unregistered a
target drive with the SML. This print will be useful for debugging the
issue where the drive addition or deletion is hanging at SML.

5. During driver load time print request, reply, sense and config page
pool's information such as its address, length and size. Also printed
sg_tablesize information.

Link: https://lore.kernel.org/r/20191226111333.26131-8-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 36c6c7f7 26-Dec-2019 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: renamed _base_after_reset_handler function

Renamed _base_after_reset_handler function to
_base_clear_outstanding_commands so that it can be used in multiple
scenarios with suitable name which matches with the operation it does.

Also renamed its child functions. No functional changes.

Link: https://lore.kernel.org/r/20191226111333.26131-4-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 3524a38e 04-Oct-2019 Dan Carpenter <dan.carpenter@oracle.com>

scsi: mpt3sas: Clean up some indenting

This line is indented too far so it's a bit confusing.

Link: https://lore.kernel.org/r/20191004100615.GA823@mwanda
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 77fd4f2c 13-Sep-2019 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: Reject NVMe Encap cmnds to unsupported HBA

If any faulty application issues an NVMe Encapsulated commands to HBA which
doesn't support NVMe protocol then driver should return the command as
invalid with the following message.

"HBA doesn't support NVMe. Rejecting NVMe Encapsulated request."

Otherwise below page fault kernel panic will be observed while building the
PRPs as there is no PRP pools allocated for the HBA which doesn't support
NVMe drives.

RIP: 0010:_base_build_nvme_prp+0x3b/0xf0 [mpt3sas]
Call Trace:
_ctl_do_mpt_command+0x931/0x1120 [mpt3sas]
_ctl_ioctl_main.isra.11+0xa28/0x11e0 [mpt3sas]
? prepare_to_wait+0xb0/0xb0
? tty_ldisc_deref+0x16/0x20
_ctl_ioctl+0x1a/0x20 [mpt3sas]
do_vfs_ioctl+0xaa/0x620
? vfs_read+0x117/0x140
ksys_ioctl+0x67/0x90
__x64_sys_ioctl+0x1a/0x20
do_syscall_64+0x60/0x190
entry_SYSCALL_64_after_hwframe+0x44/0xa9

[mkp: tweaked error string]

Link: https://lore.kernel.org/r/1568379890-18347-12-git-send-email-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 29f571f8 13-Sep-2019 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: Fail release cmnd if diag buffer is released

Return the diag buffer release command with -EINVAL status if the buffer is
already released.

Link: https://lore.kernel.org/r/1568379890-18347-10-git-send-email-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# a8a6cbcd 13-Sep-2019 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: Add app owned flag support for diag buffer

Added a new status flag named MPT3_DIAG_BUFFER_IS_APP_OWNED and it will set
whenever application registers the diag buffer & it will be cleared when
application unregisters the buffer.

When this flag is enabled, and if application issues diag buffer register
command without releasing the buffer, then register command will be failed
with -EINVAL status by saying that this buffer is already registered by the
application.

When user issues a trace buffer register command through sysfs parameter,
and if trace buffer is in released stated but not yet unregistered by the
application which was owning it, then driver will unregister the buffer by
itself and freshly register the 1MB sized trace buffer with the HBA
firmware.

Link: https://lore.kernel.org/r/1568379890-18347-9-git-send-email-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# a066f4c3 13-Sep-2019 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: Reuse diag buffer allocated at load time

The diag buffer which is allocated during driver load time or through sysfs
parameter is marked as driver allocated diag buffer.
MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED bit will be set for this buffer.

This buffer won't be de-allocated even when application issues unregister
command, driver just clears the registered status bit. Same buffer will be
reused while re-registering the same diag buffer type by any application.
While re-registering the same diag buffer type application has to register
with the same size that the buffer was allocated during driver load
time. This buffer size can be read by the application by issuing diag
'query' command.

This always makes sure that the memory is available for applications for
collecting the firmware logs. Only thing is that this won't allow the
application to re-register the diag buffer with different size, but the
buffer size which is allocated during driver load time will be enough for
most of the cases for collecting the firmware logs.

Link: https://lore.kernel.org/r/1568379890-18347-8-git-send-email-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# dd180e4e 13-Sep-2019 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: clear release bit when buffer reregistered

Clear MPT3_DIAG_BUFFER_IS_RELEASED bit once diag buffer is re-registered
after reading the buffer, else driver won't release the buffer and return
the 'diag release' command with -EINVAL status saying that buffer is
already released.

Link: https://lore.kernel.org/r/1568379890-18347-7-git-send-email-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 08e7378e 13-Sep-2019 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: Maintain owner of buffer through UniqueID

Application A has registered a diag buffer and looking for particular event
to happen to release & read the trace buffer. Meanwhile application B has
unregistered the diag buffer and now Application A can't get the required
diag buffer. So proper diag buffer ownership is missing.

Each application has to maintain its own Unique ID. Now driver has to save
the Application's UniqueID for each diag buffer type when diag buffer is
registered. And driver has to allow 'release', 'read' & 'unregister' diag
commands only if application's UniqueID matches with saved UniqueID for the
corresponding diag buffer type.

When diag buffer is registered by the driver, then the UniqueID saved by
the driver is "BRCM" (i.e. 0x4252434D) for SAS3 and above generations HBA
devices. For SAS2 HBAs, driver keeps the legacy UniqueID 0x07075900 for
maintaining compatibility with the legacy SAS2 application and this
improvement won't be applicable for SAS2 HBA devices.

Any application can own the buffer registered by the driver by sending
diag register request to driver with same buffer type and size
(Application can get the buffer size by sending 'query' command). Then
driver changes the ownership of the buffer by saving application's
UniqueID for that corresponding buffer type.

Also, application can re-register the diag buffer with same size without
un-registering it, but diag buffer should be released before re-registering
it. By allowing this, driver no need to deallocate and allocate a new
buffer for re-register command, same buffer can be re-used.

Link: https://lore.kernel.org/r/1568379890-18347-6-git-send-email-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 764f472b 13-Sep-2019 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: Free diag buffer without any status check

Memory leak can happen when diag buffer is released but not unregistered
(where buffer is deallocated) by the user. During module unload time driver
is not deallocating the buffer if the buffer is in released state.

Deallocate the diag buffer during module unload time without any diag
buffer status checks.

Link: https://lore.kernel.org/r/1568379890-18347-5-git-send-email-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 782b2818 13-Sep-2019 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: Fix clear pending bit in ioctl status

When user issues diag register command from application with required size,
and if driver unable to allocate the memory, then it will fail the register
command. While failing the register command, driver is not currently
clearing MPT3_CMD_PENDING bit in ctl_cmds.status variable which was set
before trying to allocate the memory. As this bit is set, subsequent
register command will be failed with BUSY status even when user wants to
register the trace buffer will less memory.

Clear MPT3_CMD_PENDING bit in ctl_cmds.status before returning the diag
register command with no memory status.

Link: https://lore.kernel.org/r/1568379890-18347-4-git-send-email-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 4bc50dc1 13-Sep-2019 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: Display message before releasing diag buffer

Display message before releasing the diag buffer so that user knows which
event caused the release of diag buffer.

Releasing of diag buffer means HBA firmware stops posting the firmware logs
on the registered diag buffer.

Link: https://lore.kernel.org/r/1568379890-18347-3-git-send-email-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# d04a6edf 13-Sep-2019 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: Register trace buffer based on NVDATA settings

Currently if user wishes to enable the host trace buffer during driver load
time, then user has to load the driver with module parameter
'diag_buffer_enable' set to one.

Alternatively now the user can enable host trace buffer by enabling the
following fields in manufacturing page11 in NVDATA (nvdata xml is used
while building HBA firmware image):

* HostTraceBufferMaxSizeKB - Maximum trace buffer size in KB that host can
allocate,

* HostTraceBufferMinSizeKB - Minimum trace buffer size in KB atleast host
should allocate,

* HostTraceBufferDecrementSizeKB - size by which host can reduce from
buffer size and retry the buffer allocation
when buffer allocation failed with previous
calculated buffer size.

The driver will register the trace buffer automatically without any module
parameter during boot time when above fields are enabled in manufacturing
page11 in HBA firmware.

Driver follows the following algorithm for enabling the host trace buffer
during driver load time:

* If user has loaded the driver with module parameter 'diag_buffer_enable'
set to one, then driver allocates 2MB buffer and registers this buffer
with HBA firmware for capturing the firmware trace logs.

* Else driver reads manufacture page11 data and checks whether
HostTraceBufferMaxSizeKB filed is zero or not?

- If HostTraceBufferMaxSizeKB is non-zero then driver tries to allocate
HostTraceBufferMaxSizeKB size of memory. If the buffer allocation is
successful, then it will register this buffer with HBA firmware, else
in a loop the driver will try again by reducing the current buffer size
with HostTraceBufferDecrementSizeKB size until memory allocation is
successful or buffer size falls below HostTraceBufferMinSizeKB. If the
memory allocation is successful, then the buffer will be registered
with the firmware. Else, if the buffer size falls below the
HostTraceBufferMinSizeKB, then driver won't register trace buffer with
HBA firmware.

- If HostTraceBufferMaxSizeKB is zero, then driver won't register trace
buffer with HBA firmware.

Link: https://lore.kernel.org/r/1568379890-18347-2-git-send-email-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 8dc8d29a 22-Aug-2019 Sreekanth Reddy <sreekanth.reddy@broadcom.com>

scsi: mpt3sas: Introduce module parameter to override queue depth

This patch provides a module parameter and sysfs interface to select
whether the queue depth for each device should be based on the
protocol-specific value set by the driver (the default) or the maximum
supported by the controller (can_queue).

Although we have a sysfs interface per sdev to change the queue depth
of individual scsi devices, this implementation provides a single
sysfs entry per shost to switch between the controller max and the
driver default.

[mkp: tweaked commit desc]

Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 3ac8e47b 03-Aug-2019 Suganath Prabu <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Add sysfs to know supported features

Currently with sysfs parameter "drv_support_bitmap" driver exposes whether
driver supports toolbox memory move command or not.

And application should issue the toolbox memory move command only if driver
tell that memory move tool box command is supported through this sysfs
parameter.

In future we can utilize this sysfs parameter if any new feature is added
and need to notify the same to applications.

Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# ba630ea0 03-Aug-2019 Suganath Prabu <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Support MEMORY MOVE Tool box command

Host uses the Memory Move Tool to copy data from any source/destination
combination of system memory and IOC memory.

Memory Move Tool box request contains two SGE fields, First SGE field must
contains the source buffer details described by an MPI Simple SGE. The
second SGE field must contains the destination buffer details described by
an MPI Simple SGE.

Source -> Destination

1. IOC -> IOC (Both the SGE's will be filled by application)

2. HOST -> HOST (Both the SGE's will be filled by the host,
application should give sgl_offset to first SGE offset)

3. IOC -> HOST (Application will fill the first SGE and set the
sgl_offset to second SGE and hence driver fills
the second SGE)
4. HOST -> IOC (Application will fill IOC buffer information in the
first SGE and set the sgl_offset to second SGE.
Then driver will fill the second SGE with Host buffer
information and just before posting the command to the
firmware, driver will swap these two SGEs so that first
SGE contains the HOST buffer information and second SGE
contains the IOC information.

Driver has to take care only of the 4th case, other three cases are by
default supported by the current driver design.

Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 5bb309db 03-Aug-2019 Suganath Prabu <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Enumerate SES of a managed PCIe switch

SES device of managed PCIe switch will be enumerated same as NVMe drives.

The device info type for this SES device is

MPI26_PCIE_DEVINFO_SCSI (0x4),

whereas the device info type for NVMe drives is

MPI26_PCIE_DEVINFO_NVME (0x3).

Based on this device info type driver determines whether the device is NVMe
drive or a SES device of a managed PCIe switch.

This SES device doesn't have the PCIe device page 2 information like NVMe
drives, so driver won't read PCIe device page 2 information for SES device.

This SES device uses only IEEE SGL's, So driver build's IEEE SGL's whenever
it receives any SCSI commands for this SES device.

Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# e224e03b 03-Aug-2019 Suganath Prabu <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: memset request frame before reusing

Driver gets a request frame from the free pool of DMA-able request frames
and fill in the required information and pass the address of the frame to
IOC/FW to pull the complete request frame. In certain places the driver
used the request frame allocated from the free pool without completely
clearing the previous data stored in it. The request contents were cleared
only for the size of the new request to be issued and that left out some
stale data in the unused part of the request. Though the IOC/FW is not
expected to access the request beyond the specified size, it is good
practice to clear complete request message frame.

So reinitialize the complete request message frame with 0s before using
it.

Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# f23ca2cb 03-Aug-2019 Suganath Prabu <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Add support for PCIe Lane margin

PCIe Lane margin tool box request requires IEEE sgl's and hence driver
fills the SGL field with IEEE sgl's while issuing the PCIe Lane margin
ioctl request to the HBA firmware.

Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 8f55c307 27-Jul-2019 Minwoo Im <minwoo.im@samsung.com>

scsi: mpt3sas: support target smid for [abort|query] task

We can request task management IOCTL command(MPI2_FUNCTION_SCSI_TASK_MGMT)
to /dev/mpt3ctl. If the given task_type is either abort task or query
task, it may need a field named "Initiator Port Transfer Tag to Manage" in
the IU.

Current code does not support to check target IPTT tag from the tm_request.
This patch introduces to check TaskMID given from the userspace as a target
tag. We have a rule of relationship between
(struct request *req->tag) and smid in mpt3sas_base.c:

3318 u16
3319 mpt3sas_base_get_smid_scsiio(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx,
3320 struct scsi_cmnd *scmd)
3321 {
3322 struct scsiio_tracker *request = scsi_cmd_priv(scmd);
3323 unsigned int tag = scmd->request->tag;
3324 u16 smid;
3325
3326 smid = tag + 1;

So if we want to abort a request tagged #X, then we can pass (X + 1) to
this IOCTL handler. Otherwise, user space just can pass 0 TaskMID to abort
the first outstanding smid which is legacy behaviour.

Cc: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Cc: Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>
Cc: Sathya Prakash <sathya.prakash@broadcom.com>
Cc: James E.J. Bottomley <jejb@linux.ibm.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: MPT-FusionLinux.pdl@broadcom.com
Signed-off-by: Minwoo Im <minwoo.im@samsung.com>
Acked-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 1de540a9 26-Jul-2019 Dan Carpenter <dan.carpenter@oracle.com>

scsi: mpt3sas: clean up a couple sizeof() uses

There is a copy and paste bug here. It uses EVENT_TRIGGERS size instead of
SCSI_TRIGGERS size but fortunately both size are 84 bytes so it doesn't
affect runtime.

These days the preferred style is to just say sizeof(object) instead of
sizeof(type) so I have updated the function to the latest style as well.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# c9df1442 14-Jun-2019 Tomas Henzl <thenzl@redhat.com>

scsi: mpt3sas: use DEVICE_ATTR_{RO, RW}

Use existing macros. No functional change.

[mkp: typo]

Signed-off-by: Tomas Henzl <thenzl@redhat.com>
Acked-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 078a4cc1 31-May-2019 Suganath Prabu S <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: function pointers of request descriptor

This code refactoring introduces function pointers.

Host uses Request Descriptors of different types for posting an entry onto
a request queue. Based on controller type and capabilities, host can also
use atomic descriptors other than normal descriptors. Using function
pointer will avoid if-else statements

Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# f9e3ebee 29-May-2019 Gen Zhang <blackgod016574@gmail.com>

scsi: mpt3sas_ctl: fix double-fetch bug in _ctl_ioctl_main()

In _ctl_ioctl_main(), 'ioctl_header' is fetched the first time from
userspace. 'ioctl_header.ioc_number' is then checked. The legal result is
saved to 'ioc'. Then, in condition MPT3COMMAND, the whole struct is fetched
again from the userspace. Then _ctl_do_mpt_command() is called, 'ioc' and
'karg' as inputs.

However, a malicious user can change the 'ioc_number' between the two
fetches, which will cause a potential security issues. Moreover, a
malicious user can provide a valid 'ioc_number' to pass the check in first
fetch, and then modify it in the second fetch.

To fix this, we need to recheck the 'ioc_number' in the second fetch.

Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
Acked-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# f4305749 31-Oct-2018 Suganath Prabu <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Separate out mpt3sas_wait_for_ioc

No functional changes. This section of code "wait for IOC to be
operational" is used in many places across the driver. Factor this code
out into a new mpt3sas_wait_for_ioc().

Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Reviewed-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 02abcbc2 31-Oct-2018 Suganath Prabu <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Added new #define variable IOC_OPERATIONAL_WAIT_COUNT

Added new #define variable IOC_OPERATIONAL_WAIT_COUNT and it replaces hard
coded value '10' in all the places where driver is waiting for the IOC to
become operational.

Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Reviewed-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 1c2048bd 11-Oct-2018 Christoph Hellwig <hch@lst.de>

scsi: mpt3sas: switch to generic DMA API

Switch from the legacy PCI DMA API to the generic DMA API.

Also simplify setting the DMA mask a bit.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 919d8a3f 17-Sep-2018 Joe Perches <joe@perches.com>

scsi: mpt3sas: Convert uses of pr_<level> with MPT3SAS_FMT to ioc_<level>

Use a more common logging style.

Done using the perl script below and some typing

$ git grep --name-only -w MPT3SAS_FMT -- "*.c" | \
xargs perl -i -e 'local $/; while (<>) { s/\bpr_(info|err|notice|warn)\s*\(\s*MPT3SAS_FMT\s*("[^"]+"(?:\s*\\?\s*"[^"]+"\s*){0,5}\s*),\s*ioc->name\s*/ioc_\1(ioc, \2/g; print;}'

Miscellanea for these conversions:

o Coalesce formats
o Realign arguments
o Remove unnecessary parentheses
o Use casts to u64 instead of unsigned long long where appropriate
o Convert broken pr_info uses to pr_cont
o Fix broken format string concatenation with line continuations and
excess whitespace

Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 4beb4867 15-Jun-2018 Bart Van Assche <bvanassche@acm.org>

scsi: mpt3sas: Improve kernel-doc headers

Avoids that warnings about the kernel headers appear when building with
W=1. Remove useless "@Returns - Nothing" clauses. Change "@Return - " into
"Return: ".

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Sathya Prakash <sathya.prakash@broadcom.com>
Cc: Chaitra P B <chaitra.basappa@broadcom.com>
Cc: Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# c7a35705 15-Jun-2018 Bart Van Assche <bvanassche@acm.org>

scsi: mpt3sas: Split _base_reset_handler(), mpt3sas_scsih_reset_handler() and mpt3sas_ctl_reset_handler()

Split each of these functions in three functions - one function per reset
phase. This patch does not change any functionality but makes the code
easier to read.

Note: it is much easier to review the git diff -w output after having
applied this patch than by reviewing the patch itself.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Sathya Prakash <sathya.prakash@broadcom.com>
Cc: Chaitra P B <chaitra.basappa@broadcom.com>
Cc: Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# eb0c7af2 15-Jun-2018 Bart Van Assche <bvanassche@acm.org>

scsi: mpt3sas: Annotate switch/case fall-through

This patch avoids that gcc complains about switch/case fall-through
when building with W=1.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Sathya Prakash <sathya.prakash@broadcom.com>
Cc: Chaitra P B <chaitra.basappa@broadcom.com>
Cc: Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# d37306ca 31-May-2018 Chaitra P B <chaitra.basappa@broadcom.com>

scsi: mpt3sas: Fix, False timeout prints for ioctl and other internal commands during controller reset.

When an ioctl is sent to FW, and if there is a controller reset issued
before ioctl gets completed, then in controller reset path all the pending
ioctl commands are terminated from "mpt3sas_ctl_reset_handler" function.
This will wake up the waiting ioctl commands in ioctl path and print
timeouts which are actually not timeouts.

Introduced "mpt3sas_base_check_cmd_timeout" function to check and print
whether command got timed out (or) terminated due to Host reset.

Signed-off-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# c1a6c5ac 24-Apr-2018 Chaitra P B <chaitra.basappa@broadcom.com>

scsi: mpt3sas: For NVME device, issue a protocol level reset

1) Manufacturing Page 11 contains parameters to control internal
firmware behavior. Based on AddlFlags2 field FW/Driver behaviour can
be changed, (flag tm_custom_handling is used for this)

a) For PCIe device, protocol level reset should be used if flag
tm_custom_handling is 0. Since Abort Task Set, LUN reset and Target
reset will result in a protocol level reset. Drivers should issue
only one type of this reset, if that fails then it should escalate to
a controller reset (diag reset/OCR).

b) If the driver has control over the TM reset timeout value, then
driver should use the value exposed in PCIe Device Page 2 for pcie
device (field ControllerResetTO).

Signed-off-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# cf6bf971 24-Apr-2018 Chaitra P B <chaitra.basappa@broadcom.com>

scsi: mpt3sas: Bug fix for big endian systems.

This patch fixes sparse warnings and bugs on big endian systems.

Signed-off-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 40114bde 14-Feb-2018 Suganath Prabu S <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Do not use 32-bit atomic request descriptor for Ventura controllers.

Sending I/O through 32 bit descriptors to Ventura series of controller
results in IO timeout on certain conditions. This error only occurs on
systems with high I/O activity.

Changes in this patch will prevent driver from using 32 bit descriptor
and use 64 bit Descriptors

Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# a9a08845 11-Feb-2018 Linus Torvalds <torvalds@linux-foundation.org>

vfs: do bulk POLL* -> EPOLL* replacement

This is the mindless scripted replacement of kernel use of POLL*
variables as described by Al, done by this script:

for V in IN OUT PRI ERR RDNORM RDBAND WRNORM WRBAND HUP RDHUP NVAL MSG; do
L=`git grep -l -w POLL$V | grep -v '^t' | grep -v /um/ | grep -v '^sa' | grep -v '/poll.h$'|grep -v '^D'`
for f in $L; do sed -i "-es/^\([^\"]*\)\(\<POLL$V\>\)/\\1E\\2/" $f; done
done

with de-mangling cleanups yet to come.

NOTE! On almost all architectures, the EPOLL* constants have the same
values as the POLL* constants do. But they keyword here is "almost".
For various bad reasons they aren't the same, and epoll() doesn't
actually work quite correctly in some cases due to this on Sparc et al.

The next patch from Al will sort out the final differences, and we
should be all done.

Scripted-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>


# dbec4c90 04-Jan-2018 Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: lockless command submission

Performance improvement using block layer tag.

Curent driver gets scsiio tracker and free smid from link list and array
based tracking managed by driver. Accessing list in main io path is
performance pentaly because of protection using spinlock
"scsi_lookup_lock".

In this patch:

1. Driver removes all link list access from main io path and
use scmd->request->tag to get free smid.

2. Instead of holding 'struct scsiio_tracker' in its own pool
driver can embed it into the scsi command.

Driver provides cmd_size in scsi_host_template, so that struct
scsiio_tracker is preallocated by scsi mid layer for each scsi command.

Signed-off-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 6da999fe 04-Jan-2018 Hannes Reinecke <hare@suse.de>

scsi: mpt3sas: simplify mpt3sas_scsi_issue_tm()

Move the check for outstanding commands out of the function allowing us
to simplify the overall code.

Signed-off-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# b0cd285e 04-Jan-2018 Hannes Reinecke <hare@suse.de>

scsi: mpt3sas: always use first reserved smid for ioctl passthrough

ioctl passthrough commands require a SCSIIO smid, but cannot easily
integrate with the block layer. But the driver already has reserved some
SCSIIO smids and we're only ever allowing one ioctl command at a time we
can use the first reserved smid for ioctl commands.

Signed-off-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# afc9a42b 03-Jul-2017 Al Viro <viro@zeniv.linux.org.uk>

the rest of drivers/*: annotate ->poll() instances

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>


# 45aa6a1a 31-Oct-2017 Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: NVMe drive support for BTDHMAPPING ioctl command and log info

* Added debug prints for pcie devices in ioctl debug path. Which
will be helpful for debugging.
* Added PCIe device support for ioctl BTDHMAPPING ioctl.

Signed-off-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# aff39e61 31-Oct-2017 Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Added support for nvme encapsulated request message.

* Mpt3sas driver uses the NVMe Encapsulated Request message to send an
NVMe command to an NVMe device attached to the IOC.

* Normal I/O commands like reads and writes are passed to the
controller as SCSI commands and the controller has the ability to
translate the commands to NVMe equivalent.

* This encapsulated NVMe command is used by applications to send
direct NVMe commands to NVMe drives.

Signed-off-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 016d5c35 31-Oct-2017 Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: SGL to PRP Translation for I/Os to NVMe devices

* Added support for translating the SGLs associated with incoming
commands either to IEE SGL or NVMe PRPs for NVMe devices.

* The hardware translation of IEEE SGL to NVMe PRPs has limitations
and if a command cannot be translated by hardware then it will go to
firmware and the firmware needs to translate it. This will have a
performance impact. To avoid that, the driver proactively checks
whether the translation will be done in hardware or not. If not, then
driver translates.

[mkp: clarified commit message]

Signed-off-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# c0ff7e2c 20-Sep-2017 Meng Xu <mengxu.gatech@gmail.com>

scsi: mpt3sas: remove redundant copy_from_user in _ctl_getiocinfo

Since right after the user copy, we are going to memset(&karg, 0,
sizeof(karg)), the copy_from_user is redundant

Signed-off-by: Meng Xu <mengxu.gatech@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 9a284e5c 27-Feb-2017 Masahiro Yamada <yamada.masahiro@socionext.com>

scripts/spelling.txt: add "overwritting" pattern and fix typo instances

Fix typos and add the following to the scripts/spelling.txt:

overwritting||overwriting

Link: http://lkml.kernel.org/r/1481573103-11329-29-git-send-email-yamada.masahiro@socionext.com
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>


# 459325c4 23-Jan-2017 Chaitra P B <chaitra.basappa@broadcom.com>

scsi: mpt3sas: Fix for Crusader to achieve product targets with SAS devices.

Small glitch/degraded performance in Crusader is improved with SAS
drives by removing unnecessary spinlocks while clearing scsi command in
drivers internal lookup table.

Signed-off-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 307d9075 12-Dec-2016 Adam Manzanares <adam.manzanares@wdc.com>

scsi: mpt3sas: Recognize and act on iopriority info

This patch adds support for request iopriority handling in the mpt3sas
layer. This works only when a ATA device is behind the SATL. The ATA
device also has to indicate that it supports command priorities in the
identify information that is pulled from the SATL.

Signed-off-by: Adam Manzanares <adam.manzanares@wdc.com>
Acked-by: Sreekanth Reddy <Sreekanth.Reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 81c16f83 26-Oct-2016 Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Use the new MPI 2.6 32-bit Atomic Request Descriptors for SAS35 devices.

Support Atomic Request Descriptors for Ventura/SAS35 devices.

Signed-off-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 998f26ae 26-Oct-2016 Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Added Device ID's for SAS35 devices and updated MPI header.

Added Device ID's for SAS35 devices (Ventura, Crusader, Harpoon &
Tomcat) and updated mpi header file for the same. Also added
"is_gen35_ioc" to MPT3SAS_ADAPTER structure for identifying SAS35 adapters.

Signed-off-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# c696f7b8 26-Oct-2016 Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>

scsi: mpt3sas: Implement device_remove_in_progress check in IOCTL path

When device missing event arrives, device_remove_in_progress bit will be
set and hence driver has to stop sending IOCTL commands.Now the check has
been added in IOCTL path to test device_remove_in_progress bit is set, if
so then IOCTL will be failed printing failure message.

Signed-off-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 8bbb1cf6 28-Jul-2016 Calvin Owens <calvinowens@fb.com>

mpt3sas: Fix warnings exposed by W=1

Trivial non-functional changes for a couple annoying things:

1) Functions local to files are not declared static, which is
frustrating when reading the code because it's non-obvious at first
glance what's actually called from other files.

2) Set-but-unused variables abound, presumably to mask -Wunused-result
errors in the past. None of these are flagged today though (with one
exception noted below), so remove them.

Fixing (2) exposed the fact that we improperly ignore the return value
of scsi_device_reprobe() in _scsih_reprobe_lun(). Fixing the calling
code to deal with the potential error is non-trivial, so for now just
WARN().

Signed-off-by: Calvin Owens <calvinowens@fb.com>
Acked-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 98c56ad3 28-Jul-2016 Calvin Owens <calvinowens@fb.com>

mpt3sas: Eliminate dead sleep_flag code

With the exception of a single call to wait_for_doorbell_int(), all this
conditional sleeping code is dead. So delete it.

Signed-off-by: Calvin Owens <calvinowens@fb.com>
Acked-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 96902835 28-Jul-2016 Calvin Owens <calvinowens@fb.com>

mpt3sas: Eliminate conditional locking in mpt3sas_scsih_issue_tm()

This flag that conditionally acquires the mutex is confusing and prone
to bugginess: refactor it into two separate function calls, and make the
unlocked one complain if it's called outside the mutex.

Signed-off-by: Calvin Owens <calvinowens@fb.com>
Acked-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 03d1fb3a 27-Jan-2016 Suganath prabu Subramani <suganath-prabu.subramani@avagotech.com>

mpt3sas: Fix for Asynchronous completion of timedout IO and task abort of timedout IO.

Track msix of each IO and use the same msix for issuing abort to timed
out IO. With this driver will process IO's reply first followed by TM.

Signed-off-by: Suganath prabu Subramani <suganath-prabu.subramani@avagotech.com>
Signed-off-by: Chaitra P B <chaitra.basappa@avagotech.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 869817f9 27-Jan-2016 Suganath prabu Subramani <suganath-prabu.subramani@avagotech.com>

mpt3sas: Fix static analyzer(coverity) tool identified defects

1.Wrong size of argument is being passed
The size of struct being passed as an argument to memset func and area of
memory being pointed by an instance of struct in memset func should be of
same structure type.
2.Dereference null return value
3.Array compared against '0'
Check whether value pointed by particular index of an array is null or not
in "if" statement.

Signed-off-by: Suganath prabu Subramani <suganath-prabu.subramani@avagotech.com>
Signed-off-by: Chaitra P B <chaitra.basappa@avagotech.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# b130b0d5 27-Jan-2016 Suganath prabu Subramani <suganath-prabu.subramani@avagotech.com>

mpt3sas: Added support for high port count HBA variants.

Updated hardware description headers with MPI v2.6 and
mpt3sas_pci_table[] with vendor_ids, device_ids of Cutlass and Intruder
HBA which have support for 4 ports.

Signed-off-by: Suganath prabu Subramani <suganath-prabu.subramani@avagotech.com>
Signed-off-by: Chaitra P B <chaitra.basappa@avagotech.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# c84b06a4 11-Nov-2015 Sreekanth Reddy <sreekanth.reddy@avagotech.com>

mpt3sas: Single driver module which supports both SAS 2.0 & SAS 3.0 HBAs

Modified the mpt3sas driver to have a single driver module which
supports both SAS 2.0 & SAS 3.0 HBA devices.

* Added SAS 2.0 HBA device IDs to the mpt3sas_pci_table pci table.

* Created two separate SCSI host templates for SAS2 and SAS3 HBAs so
that, during the driver load time driver can use corresponding host
template(based the pci device ID) while registering a scsi host
adapter instance for that pci device.

* Registered two IOCTL devices, mpt2ctl is for SAS2 HBAs & mpt3ctl for
SAS3 HBAs. Also updated the code to make sure that mpt2ctl device
processes only those ioctl cmds issued for the SAS2 HBAs and mpt3ctl
device processes only those ioctl cmds issued for the SAS3 HBAs.

* Added separate indexing for SAS2 and SAS3 HBAs.

* Replaced compile time check 'MPT2SAS_SCSI' to run time check
'hba_mpi_version_belonged' whereever needed.

* Aliased this merged driver to mpt2sas using MODULE_ALIAS.

* Moved global varaible 'driver_name' to per adapter instance variable.

* Created two raid function template and used corresponding raid
function templates based on the run time check
'hba_mpi_version_belonged'.

* Moved mpt2sas_warpdrive.c file from mpt2sas to mpt3sas folder and
renamed it as mpt3sas_warpdrive.c.

* Also renamed the functions in mpt3sas_warpdrive.c file to follow
current driver function name convention.

* Updated the Makefile to build mpt3sas_warpdrive.o file for these
WarpDrive-specific functions.

* Also in function mpt3sas_setup_direct_io(), used sector_div() API
instead of division operator (which gives compilation errors on 32 bit
machines).

* Removed mpt2sas files, mpt2sas directory & mpt3sas_module.c file.

* Added module parameter 'hbas_to_enumerate' which permits using this
merged driver as a legacy mpt2sas driver or as a legacy mpt3sas
driver.

Here are the available options for this module parameter:

0 - Merged driver which enumerates both SAS 2.0 & SAS 3.0 HBAs
1 - Acts as legacy mpt2sas driver, which enumerates only SAS 2.0 HBAs
2 - Acts as legacy mpt3sas driver, which enumerates only SAS 3.0 HBAs

* Removed mpt2sas entries from SCSI's Kconfig and Makefile files.

Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@avagotech.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 08c4d550 11-Nov-2015 Sreekanth Reddy <sreekanth.reddy@avagotech.com>

mpt3sas: setpci reset kernel oops fix

setpci reset on nytro warpdrive card along with sysfs access and cli
ioctl access resulted in kernel oops

1. pci_access_mutex lock added to provide synchronization between IOCTL,
sysfs, PCI resource handling path

2. gioc_lock spinlock to protect list operations over multiple
controllers

This patch is ported from commit 6229b414b3ad ("mpt2sas: setpci reset
kernel oops fix").

Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@avagotech.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 42263095 11-Nov-2015 Sreekanth Reddy <sreekanth.reddy@avagotech.com>

mpt3sas: sysfs attribute to report Backup Rail Monitor Status

A new sysfs shost attribute called "BMR_status" is implemented to report
Backup Rail Monitor status.

This attribute is located in:

/sys/class/scsi_host/host#/BMR_status

When reading this adapter attribute, the driver will output the state of
GPIO[24]. It returns "0" if BMR is healthy and "1" for failure.

If it returns an empty string then it means that there was an error
while obtaining the BMR status. Check dmesg for what error has occurred.

This sysfs shost attribute is mainly for WarpDrive controllers.

This commit is a port of 6c265660c262 ("mpt2sas: Provide sysfs attribute
to report Backup Rail Monitor Status").

Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@avagotech.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 7786ab6a 11-Nov-2015 Sreekanth Reddy <sreekanth.reddy@avagotech.com>

mpt3sas: Ported WarpDrive product SSS6200 support

Ported the following list of WarpDrive-specific patches:

1. commit 0bdccdb0a090ad8dc5f851cad5e843244c410ee8 ("mpt2sas: WarpDrive
New product SSS6200 support added")

2. commit 82a452581230b3ffc9d6475dffdb2568497b5fec ("mpt2sas: WarpDrive
Infinite command retries due to wrong scsi command entry in MPI
message")

3. commit ba96bd0b1d4a4e11f23671e1f375a5c8f46b0fe7 ("mpt2sas: Support
for greater than 2TB capacity WarpDrive")

4. commit 4da7af9494b2f98a1503a2634059300c3e4615e6 ("mpt2sas: Do not
retry a timed out direct IO for Warpdrive")

5. commit daeaa9df92bd742f4e6d4d6039d689277a8e31bd ("mpt2sas: Avoid type
casting for direct I/O commands").

Also set the mpt2_ioctl_iocinfo adapter_type to:

1. MPT3_IOCTL_INTERFACE_SAS3 for Gen3 HBAs

2. MPT2_IOCTL_INTERFACE_SAS2_SSS6200 for Warp Drive

3. MPT2_IOCTL_INTERFACE_SAS2 for other Gen2 HBAs

Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@avagotech.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# af009411 11-Nov-2015 Sreekanth Reddy <sreekanth.reddy@avagotech.com>

mpt2sas, mpt3sas: Remove SCSI_MPTXSAS_LOGGING entry from Kconfig

Currently there is a logging level option provided for each of our
drivers in the kernel configuration utility. Users can enable this
option to get more verbose information. By default it is enabled.

Only when this option is enabled will the functions which display the
required information get compiled in.

As we are merging the both drivers we can no longer provide this
configuration option. Remove the SCSI_MPTXSAS_LOGGING entry from Kconfig
and unconditionally enable logging (by removing the #ifdef
CONFIG_SCSI_MPT3SAS_LOGGING preprocessor check conditions) so that all
functions which are defined to display more verbose information get
compiled in.

Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@avagotech.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# d357e84d 11-Nov-2015 Sreekanth Reddy <sreekanth.reddy@avagotech.com>

mpt3sas: Define 'hba_mpi_version_belonged' IOC variable

1. Use 'hba_mpi_version_belonged' IOC varable to uniquely identify each
individual generation driver functionality at runtime.

2. Declare global variable 'driver_name' and use this variable while
reserving PCI regions and while allocating the IRQs.

Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@avagotech.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 7497392a 11-Nov-2015 Sreekanth Reddy <sreekanth.reddy@avagotech.com>

mpt3sas: Move Gen3 HBA's device registration to a separate file

Created a mpt3sas_module.c file for mpt3sas driver where it can register
SAS3 HBA devices with PCI, SML, IOCTL subsystems. Also removed the
corresponding interfaces from mpt3sas_scsih.c file.

Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@avagotech.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# 8a7e4c24 11-Nov-2015 Sreekanth Reddy <sreekanth.reddy@avagotech.com>

mpt3sas: Added mpt2sas driver definitions

1. Added mpt2sas driver related macros in mpt3sas header files

2. Made scsi host's, raid class', pci's, ioctl's callback functions
global so that both drivers can use them.

Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@avagotech.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>


# a03bd153 11-Jan-2015 Sreekanth Reddy <sreekanth.reddy@avagotech.com>

mpt2sas, mpt3sas: Update attribution language to Avago

Copyright, Trademark & Confidentiality legal statements throughout the
source code changed from LSI to Avago.

Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@avagotech.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>


# a4ffce0d 12-Sep-2014 Sreekanth Reddy <sreekanth.reddy@avagotech.com>

mpt3sas: Copyright in driver sources is updated for year the 2014.

Copyright in driver sources is updated for year the 2014.

Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@avagotech.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>


# c62e46de 27-Mar-2014 Matthew Wilcox <willy@infradead.org>

mpt3sas: Remove uses of serial_number

The mpt3sas_scsih_issue_tm() function does not use the 'serial_number'
argument passed to it. Removing it removes the last vestiges of the
scsi_cmnd's serial_number field from this driver.

Signed-off-by: Matthew Wilcox <matthew.r.wilcox@intel.com>
Reviewed-by: Nicholas Bellinger <nab@linux-iscsi.org>
Reviewed-by: Praveen Krishnamoorthy <Praveen.krishnamoorthy@lsi.com>
Acked-by: Sreekanth Reddy <Sreekanth.reddy@lsi.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>


# 48e3b985 28-Jun-2013 Sreekanth Reddy <Sreekanth.Reddy@lsi.com>

[SCSI] mpt3sas: 2013 source code copyright

The Copyright String in all mpt3sas files are changed to 2012-2013.

Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@lsi.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>


# 70ab27dd 15-Apr-2013 Al Viro <viro@zeniv.linux.org.uk>

mpt3sas: don't wank with fasync on ->release()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>


# 3735660d 03-Dec-2012 Sachin Kamat <sachin.kamat@linaro.org>

[SCSI] mpt3sas: Remove unneeded version.h header inclusion

linux/version.h is not necessary as detected by checkversion.pl script.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Acked-by: "Sreekanth Reddy" <Sreekanth.reddy@lsi.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>


# 66331e8c 07-Dec-2012 Dan Carpenter <dan.carpenter@oracle.com>

[SCSI] mpt3sas: cut and paste bug storing trigger mpi

ioc->diag_trigger_mpi is an SL_WH_MPI_TRIGGERS_T struct.

There is a cut and paste error here and SL_WH_EVENT_TRIGGERS_T is used
instead of SL_WH_MPI_TRIGGERS_T. Since the SL_WH_EVENT_TRIGGERS_T is
smaller than SL_WH_MPI_TRIGGERS_T, it means we only clear part of the
buffer.

I've changed it to use sizeof(ioc->diag_trigger_mpi) which is a bit
simpler.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: "Sreekanth Reddy" <Sreekanth.reddy@lsi.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>


# f92363d1 29-Nov-2012 Sreekanth Reddy <Sreekanth.Reddy@lsi.com>

[SCSI] mpt3sas: add new driver supporting 12GB SAS

These driver files are initially, substantially similar to mpt2sas but,
because mpt2sas is going into maintenance mode and mp3sas will become heavily
developed, we elected to keep the code bases separate.

Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@lsi.com>
Reviewed-by: Nagalakshmi Nandigama <Nagalakshmi.Nandigama@lsi.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>