OSDN Git Service

tomoyo/tomoyo-test1.git
4 years agoscsi: lpfc: Fix ADISC reception terminating login state if a NVME target
James Smart [Wed, 14 Aug 2019 23:56:39 +0000 (16:56 -0700)]
scsi: lpfc: Fix ADISC reception terminating login state if a NVME target

If a target issues an ADISC to the port and the target is a NVME target,
the driver is inadvertantly invalidating the login and marking the remote
port as logged out. Communication with the target is lost.

Revise the ADISC check so that FCP or NVME targets will be marked valid at
the end of ADISC processing.  Enhance logging to recognize condition
better.

Signed-off-by: Dick Kennedy <dick.kennedy@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: lpfc: Fix discovery when target has no GID_FT information
James Smart [Wed, 14 Aug 2019 23:56:38 +0000 (16:56 -0700)]
scsi: lpfc: Fix discovery when target has no GID_FT information

Some remote ports may be slow in registering their GID_FT protocol
information with the fabric. If the remote port is an initiator, it may
send PLOGI to the port before the GID_FT logic is complete. Meaning, after
accepting the PLOGI, when the driver may see no response to the GID_FT that
is issued after the login to determine the protocols supported so that
proper PRLI's may be transmit. If the driver has no fc4 information, it
currently stops and the remote port is not discovered.

Fix by issuing a LOGO when there is no GID_FT information.  The LOGO
completion handling will attempt to re-login if the nport_id is still
present.

Signed-off-by: Dick Kennedy <dick.kennedy@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: lpfc: Fix port relogin failure due to GID_FT interaction
James Smart [Wed, 14 Aug 2019 23:56:37 +0000 (16:56 -0700)]
scsi: lpfc: Fix port relogin failure due to GID_FT interaction

In cases of remote-port-side cable pull/replug, there happens to be a
target that upon replug will send the port a PLOGI, a PRLI, and a LOGO.
When this sequence is received by the driver, the PLOGI accepted and a
GFT_ID is issued to find the protocol support for the remote port. While
the GFT_ID is outstanding, a LOGO is received. The driver logs the remote
port out and unregisters the RPI and schedules a new PLOGI transmission.
However, the GFT_ID was not terminated. When it completed, the driver
attempted to transition the remote port to PRLI transmission, which cancels
the PLOGI scheduling. The PRLI transmit attempt is rejected by the adapter
as the remote port is not logged in. No retry is attempted as it's expected
the logout is noted and the supposedly scheduled PLOGI should address the
state. As there is no PLOGI, the remote port does not get re-discovered.

Fix by aborting the outstanding GFT_ID if the related remote port is logged
out.

Ensure a PRLI transmit attempt only occurs if the remote port is logging
in. This avoids the incorrect attempt while logged out.

Signed-off-by: Dick Kennedy <dick.kennedy@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: lpfc: Fix leak of ELS completions on adapter reset
James Smart [Wed, 14 Aug 2019 23:56:36 +0000 (16:56 -0700)]
scsi: lpfc: Fix leak of ELS completions on adapter reset

If the adapter is reset while there are outstanding ELS's, subsequent
reinitialization of the adapter will fail as it has not recovered all of
the io contexts relative to the ELS's.

If an ELS timed out or otherwise failed and an the ELS was attempted to be
aborted (which changes the ELS completion context), in causes where the
driver generates completions for the outstanding IO as the adapter would
not due to being reset, the driver released only the ELS context and failed
to release the abort context.  When the adapter went to reinit, as it had
not received all of the contexts, it failed to reinit.

Fix by having the ELS completion handler identify the driver-generated
completion status and release the abort context.

Signed-off-by: Dick Kennedy <dick.kennedy@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: lpfc: Fix failure to clear non-zero eq_delay after io rate reduction
James Smart [Wed, 14 Aug 2019 23:56:35 +0000 (16:56 -0700)]
scsi: lpfc: Fix failure to clear non-zero eq_delay after io rate reduction

Unusually high IO latency can be observed with little IO in progress. The
latency may remain high regardless of amount of IO and can only be cleared
by forcing lpfc_fcp_imax values to non-zero and then back to zero.

The driver's eq_delay mechanism that scales the interrupt coalescing based
on io completion load failed to reduce or turn off coalescing when load
decreased. Specifically, if no io completed on a cpu within an eq_delay
polling window, the eq delay processing was skipped and no change was made
to the coalescing values. This left the coalescing values set when they
were no longer applicable.

Fix by always clearing the percpu counters for each time period and always
run the eq_delay calculations if an eq has a non-zero coalescing value.

Signed-off-by: Dick Kennedy <dick.kennedy@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: lpfc: Fix crash on driver unload in wq free
James Smart [Wed, 14 Aug 2019 23:56:34 +0000 (16:56 -0700)]
scsi: lpfc: Fix crash on driver unload in wq free

If a timer routine uses workqueues, it could fire before the workqueue is
allocated.

Fix by allocating the workqueue before the timer routines are setup

Signed-off-by: Dick Kennedy <dick.kennedy@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: lpfc: Fix ELS field alignments
James Smart [Wed, 14 Aug 2019 23:56:33 +0000 (16:56 -0700)]
scsi: lpfc: Fix ELS field alignments

After seeing some interoperability issues with ADISC, it was determined the
ELS definitions in lpfc were using types that allowed the compiler to add
pad to the structure, causing the structure to no longer be per spec. The
offending structures are ADISC, FAN, and RNID.

This patch implements the simple fix of eliminating the pad by forcing the
compiler to pack the structure. Care was taken to ensure field accesses
won't be by operations that would hit a bad field alignment.

The better solution would be to convert to the uapi fc header definitions,
but the number of changes required to do is rather intrusive so this course
of action was deferred.

Signed-off-by: Dick Kennedy <dick.kennedy@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: lpfc: Fix PLOGI failure with high remoteport count
James Smart [Wed, 14 Aug 2019 23:56:32 +0000 (16:56 -0700)]
scsi: lpfc: Fix PLOGI failure with high remoteport count

When connected to a high number of remote ports, the driver is encountering
PLOGI errors.  The errors are due to adapter detected failures indicating
illegal field values.

Turns out the driver was prematurely clearing an RPI bitmask before waiting
for an UNREG_RPI mailbox completion. This allowed the RPI to be reused
before it was actually available.

Fix by clearing RPI bitmask only after UNREG_RPI mailbox completion.

Signed-off-by: Dick Kennedy <dick.kennedy@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: lpfc: Limit xri count for kdump environment
James Smart [Wed, 14 Aug 2019 23:56:31 +0000 (16:56 -0700)]
scsi: lpfc: Limit xri count for kdump environment

scsi-mq operation inherently performs pre-allocation of resources for
blk-mq request queues. Even though the kdump environment reduces the
configuration to a single CPU, thus 1 hardware queue, which helps
significantly, the resources are still rather large due to the per request
allocations. blk-mq pre-allocations can be over 4KB per request.  With
adapter can_queue values in the 4k or 8k range, this can easily be 32MBs
before any other driver memory is factored in.  Driver SGL DMA buffer
allocation can be up to 8KB per request as well adding an additional
64MB. Totals are well over 100MB for a single shost.  Given kdump memory
auto-sizing utilities don't accommodate this amount of memory well, it's
very possible for kdump to fail due to lack of memory.

Fix by having the driver recognize that it is booting within a kdump
context and reduce the number of requests it will support to a more
reasonable value.

Signed-off-by: Dick Kennedy <dick.kennedy@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: lpfc: remove NULL check before some freeing functions
Hariprasad Kelam [Sun, 21 Jul 2019 11:42:29 +0000 (17:12 +0530)]
scsi: lpfc: remove NULL check before some freeing functions

As dma_pool_destroy and mempool_destroy functions has NULL check. We may
not need NULL check before calling them.

Fix below warnings reported by coccicheck
./drivers/scsi/lpfc/lpfc_mem.c:252:2-18: WARNING: NULL check before some
freeing functions is not needed.
./drivers/scsi/lpfc/lpfc_mem.c:255:2-18: WARNING: NULL check before some
freeing functions is not needed.
./drivers/scsi/lpfc/lpfc_mem.c:258:2-18: WARNING: NULL check before some
freeing functions is not needed.
./drivers/scsi/lpfc/lpfc_mem.c:261:2-18: WARNING: NULL check before some
freeing functions is not needed.
./drivers/scsi/lpfc/lpfc_mem.c:265:2-18: WARNING: NULL check before some
freeing functions is not needed.
./drivers/scsi/lpfc/lpfc_mem.c:269:2-17: WARNING: NULL check before some
freeing functions is not needed.

Signed-off-by: Hariprasad Kelam <hariprasad.kelam@gmail.com>
Reviewed-by: James Smart <james.smart@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: ufs-qcom: Make structure ufs_hba_qcom_vops constant
Nishka Dasgupta [Mon, 19 Aug 2019 07:55:57 +0000 (13:25 +0530)]
scsi: ufs-qcom: Make structure ufs_hba_qcom_vops constant

Static structure ufs_hba_qcom_vops, of type ufs_hba_variant_ops, is used
only once, when it is passed as the second argument to function
ufshcd_pltfrm_init(). In the definition of ufshcd_pltfrm_init(), its second
parameter (corresponding to ufs_hba_qcom_vops) is declared as
constant. Hence declare ufs_hba_qcom_vops itself constant as well to
protect it from unintended modification.  Issue found with Coccinelle.

Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
Reviewed-by: Vivek Gautam <vivek.gautam@codeaurora.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: lpfc: use spin_lock_irqsave in IRQ context
Fuqian Huang [Mon, 12 Aug 2019 08:31:34 +0000 (16:31 +0800)]
scsi: lpfc: use spin_lock_irqsave in IRQ context

As spin_unlock_irq will enable interrupts.
Function lpfc_findnode_rpi is called from
    lpfc_sli_abts_err_handler (./drivers/scsi/lpfc/lpfc_sli.c)
 <- lpfc_sli_async_event_handler
 <- lpfc_sli_process_unsol_iocb
 <- lpfc_sli_handle_fast_ring_event
 <- lpfc_sli_fp_intr_handler
 <- lpfc_sli_intr_handler
 and lpfc_sli_intr_handler is an interrupt handler.

Interrupts are enabled in interrupt handler.  Use
spin_lock_irqsave/spin_unlock_irqrestore instead of spin_(un)lock_irq in
IRQ context to avoid this.

Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com>
Reviewed-by: James Smart <james.smart@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: lpfc: remove redundant code
Fuqian Huang [Thu, 8 Aug 2019 01:35:25 +0000 (09:35 +0800)]
scsi: lpfc: remove redundant code

Remove the redundant initialization code.

Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com>
Reviewed-by: James Smart <james.smart@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: fnic: remove redundant assignment of variable rc
Colin Ian King [Tue, 13 Aug 2019 13:23:49 +0000 (14:23 +0100)]
scsi: fnic: remove redundant assignment of variable rc

Variable ret is initialized to a value that is never read and it is
re-assigned later and immediately returns. Clean up the code by removing
rc and just returning 0.

[mkp: typo]

Addresses-Coverity: ("Unused value")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Karan Tilak Kumar <kartilak@cisco.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: cleanup trace buffer initialization
Martin Wilck [Wed, 14 Aug 2019 13:28:29 +0000 (13:28 +0000)]
scsi: qla2xxx: cleanup trace buffer initialization

Avoid code duplication between qla2x00_alloc_offload_mem() and
qla2x00_alloc_fw_dump() by moving the FCE and EFT buffer allocation and
initialization to separate functions. Cleanly track failure and success by
making sure that the ha->eft, ha->fce and respective eft_dma, fce_dma
members are set if and only if the buffers are properly allocated and
initialized. Avoid pointless buffer reallocation.  Eliminate some goto
statements. Make sure the fce_enabled flag is cleared when the FCE buffer
is freed.

Fixes: ad0a0b01f088 ("scsi: qla2xxx: Fix Firmware dump size for Extended login and Exchange Offload")
Fixes: a28d9e4ef997 ("scsi: qla2xxx: Add support for multiple fwdump templates/segments")
Cc: Joe Carnuccio <joe.carnuccio@cavium.com>
Cc: Quinn Tran <qutran@marvell.com>
Cc: Himanshu Madhani <hmadhani@marvell.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin Wilck <mwilck@suse.com>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: qla2x00_alloc_fw_dump: set ha->eft
Martin Wilck [Wed, 14 Aug 2019 13:28:27 +0000 (13:28 +0000)]
scsi: qla2xxx: qla2x00_alloc_fw_dump: set ha->eft

In qla2x00_alloc_fw_dump(), an existing EFT buffer (e.g. from previous
invocation of qla2x00_alloc_offload_mem()) is freed.  The buffer is then
re-allocated, but without setting the eft and eft_dma fields to the new
values.

Fixes: a28d9e4ef997 ("scsi: qla2xxx: Add support for multiple fwdump templates/segments")
Cc: Joe Carnuccio <joe.carnuccio@cavium.com>
Cc: Quinn Tran <qutran@marvell.com>
Cc: Himanshu Madhani <hmadhani@marvell.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin Wilck <mwilck@suse.com>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: use __u{8,16,32,64} instead of uint{8,16,32,64}_t in uapi headers
Masahiro Yamada [Sun, 21 Jul 2019 14:25:02 +0000 (23:25 +0900)]
scsi: use __u{8,16,32,64} instead of uint{8,16,32,64}_t in uapi headers

When CONFIG_UAPI_HEADER_TEST=y, exported headers are compile-tested to make
sure they can be included from user-space.

Currently, scsi_bsg_fc.h, scsi_netlink.h, and scsi_netlink_fc.h are
excluded from the test coverage. To make them join the compile-test, we
need to fix the build errors attached below.

For a case like this, we decided to use __u{8,16,32,64} variable types in
this discussion:

  https://lkml.org/lkml/2019/6/5/18

Build log:

  CC      usr/include/scsi/scsi_netlink_fc.h.s
  CC      usr/include/scsi/scsi_netlink.h.s
  CC      usr/include/scsi/scsi_bsg_fc.h.s
In file included from ./usr/include/scsi/scsi_netlink_fc.h:10:0,
                 from <command-line>:32:
./usr/include/scsi/scsi_netlink.h:29:2: error: unknown type name  uint8_t
  uint8_t version;
  ^~~~~~~
./usr/include/scsi/scsi_netlink.h:30:2: error: unknown type name  uint8_t
  uint8_t transport;
  ^~~~~~~
./usr/include/scsi/scsi_netlink.h:31:2: error: unknown type name  uint16_t
  uint16_t magic;
  ^~~~~~~~
./usr/include/scsi/scsi_netlink.h:32:2: error: unknown type name  uint16_t
  uint16_t msgtype;
  ^~~~~~~~
  CC      usr/include/rdma/vmw_pvrdma-abi.h.s
./usr/include/scsi/scsi_netlink.h:33:2: error: unknown type name  uint16_t
  uint16_t msglen;
  ^~~~~~~~
./usr/include/scsi/scsi_netlink.h:34:33: error:  uint64_t  undeclared here (not in a function); did you mean  __uint128_t ?
 } __attribute__((aligned(sizeof(uint64_t))));
                                 ^~~~~~~~
                                 __uint128_t
./usr/include/scsi/scsi_netlink.h:78:2: error: expected specifier-qualifier-list before  uint64_t
  uint64_t vendor_id;
  ^~~~~~~~
In file included from <command-line>:32:0:
./usr/include/scsi/scsi_netlink_fc.h:46:2: error: expected specifier-qualifier-list before  uint64_t
  uint64_t seconds;
  ^~~~~~~~
make[2]: *** [scripts/Makefile.build;302: usr/include/scsi/scsi_netlink_fc.h.s] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from <command-line>:32:0:
./usr/include/scsi/scsi_netlink.h:29:2: error: unknown type name  uint8_t
  uint8_t version;
  ^~~~~~~
./usr/include/scsi/scsi_netlink.h:30:2: error: unknown type name  uint8_t
  uint8_t transport;
  ^~~~~~~
./usr/include/scsi/scsi_netlink.h:31:2: error: unknown type name  uint16_t
  uint16_t magic;
  ^~~~~~~~
./usr/include/scsi/scsi_netlink.h:32:2: error: unknown type name  uint16_t
  uint16_t msgtype;
  ^~~~~~~~
./usr/include/scsi/scsi_netlink.h:33:2: error: unknown type name  uint16_t
  uint16_t msglen;
  ^~~~~~~~
./usr/include/scsi/scsi_netlink.h:34:33: error:  uint64_t  undeclared here (not in a function); did you mean  __uint128_t ?
 } __attribute__((aligned(sizeof(uint64_t))));
                                 ^~~~~~~~
                                 __uint128_t
./usr/include/scsi/scsi_netlink.h:78:2: error: expected specifier-qualifier-list before  uint64_t
  uint64_t vendor_id;
  ^~~~~~~~
make[2]: *** [scripts/Makefile.build;302: usr/include/scsi/scsi_netlink.h.s] Error 1
In file included from <command-line>:32:0:
./usr/include/scsi/scsi_bsg_fc.h:69:2: error: unknown type name  uint8_t
  uint8_t  reserved;
  ^~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:72:2: error: unknown type name  uint8_t
  uint8_t  port_id[3];
  ^~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:90:2: error: unknown type name  uint8_t
  uint8_t  reserved;
  ^~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:93:2: error: unknown type name  uint8_t
  uint8_t  port_id[3];
  ^~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:114:2: error: unknown type name  uint8_t
  uint8_t  command_code;
  ^~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:117:2: error: unknown type name  uint8_t
  uint8_t  port_id[3];
  ^~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:154:2: error: unknown type name  uint32_t
  uint32_t status;  /* See FC_CTELS_STATUS_xxx */
  ^~~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:158:3: error: unknown type name  uint8_t
   uint8_t action;  /* fragment_id for CT REJECT */
   ^~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:159:3: error: unknown type name  uint8_t
   uint8_t reason_code;
   ^~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:160:3: error: unknown type name  uint8_t
   uint8_t reason_explanation;
   ^~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:161:3: error: unknown type name  uint8_t
   uint8_t vendor_unique;
   ^~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:177:2: error: unknown type name  uint8_t
  uint8_t  reserved;
  ^~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:180:2: error: unknown type name  uint8_t
  uint8_t  port_id[3];
  ^~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:185:2: error: unknown type name  uint32_t
  uint32_t preamble_word0; /* revision & IN_ID */
  ^~~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:186:2: error: unknown type name  uint32_t
  uint32_t preamble_word1; /* GS_Type, GS_SubType, Options, Rsvd */
  ^~~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:187:2: error: unknown type name  uint32_t
  uint32_t preamble_word2; /* Cmd Code, Max Size */
  ^~~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:207:2: error: unknown type name  uint64_t
  uint64_t vendor_id;
  ^~~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:210:2: error: unknown type name  uint32_t
  uint32_t vendor_cmd[0];
  ^~~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:217:2: error: unknown type name  uint32_t
  uint32_t vendor_rsp[0];
  ^~~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:236:2: error: unknown type name  uint8_t
  uint8_t els_code;
  ^~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:254:2: error: unknown type name  uint32_t
  uint32_t preamble_word0; /* revision & IN_ID */
  ^~~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:255:2: error: unknown type name  uint32_t
  uint32_t preamble_word1; /* GS_Type, GS_SubType, Options, Rsvd */
  ^~~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:256:2: error: unknown type name  uint32_t
  uint32_t preamble_word2; /* Cmd Code, Max Size */
  ^~~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:268:2: error: unknown type name  uint32_t
  uint32_t msgcode;
  ^~~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:292:2: error: unknown type name  uint32_t
  uint32_t result;
  ^~~~~~~~
./usr/include/scsi/scsi_bsg_fc.h:295:2: error: unknown type name  uint32_t
  uint32_t reply_payload_rcv_len;
  ^~~~~~~~

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: esas2r: Prefer pcie_capability_read_word()
Frederick Lawler [Thu, 18 Jul 2019 02:07:44 +0000 (21:07 -0500)]
scsi: esas2r: Prefer pcie_capability_read_word()

Commit 8c0d3a02c130 ("PCI: Add accessors for PCI Express Capability") added
accessors for the PCI Express Capability so that drivers didn't need to be
aware of differences between v1 and v2 of the PCI Express Capability.

Replace pci_read_config_word() and pci_write_config_word() calls with
pcie_capability_read_word() and pcie_capability_write_word().

Signed-off-by: Frederick Lawler <fred@fredlawl.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: csiostor: Prefer pcie_capability_read_word()
Frederick Lawler [Thu, 18 Jul 2019 02:07:43 +0000 (21:07 -0500)]
scsi: csiostor: Prefer pcie_capability_read_word()

Commit 8c0d3a02c130 ("PCI: Add accessors for PCI Express Capability") added
accessors for the PCI Express Capability so that drivers didn't need to be
aware of differences between v1 and v2 of the PCI Express Capability.

Replace pci_read_config_word() and pci_write_config_word() calls with
pcie_capability_read_word() and pcie_capability_write_word().

Signed-off-by: Frederick Lawler <fred@fredlawl.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: sym53c8xx_2: remove redundant assignment to retv
Colin Ian King [Fri, 9 Aug 2019 17:59:32 +0000 (18:59 +0100)]
scsi: sym53c8xx_2: remove redundant assignment to retv

Variable retv is initialized to a value that is never read and it is
re-assigned later. The initialization is redundant and can be removed.

Addresses-Coverity: ("Unused value")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: pmcraid: Fix a typo - pcmraid --> pmcraid
Christophe JAILLET [Fri, 9 Aug 2019 15:02:14 +0000 (17:02 +0200)]
scsi: pmcraid: Fix a typo - pcmraid --> pmcraid

This should be 'pmcraid', not 'pcmraid'

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: fas216: Mark expected switch fall-throughs
Gustavo A. R. Silva [Tue, 6 Aug 2019 08:29:02 +0000 (03:29 -0500)]
scsi: fas216: Mark expected switch fall-throughs

Mark switch cases where we are expecting to fall through.

Fix the following warnings (Building: rpc_defconfig arm):

drivers/scsi/arm/fas216.c: In function  fas216_disconnect_intr :
drivers/scsi/arm/fas216.c:913:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
   if (fas216_get_last_msg(info, info->scsi.msgin_fifo) == ABORT) {
      ^
drivers/scsi/arm/fas216.c:919:2: note: here
  default:    /* huh?     */
  ^~~~~~~
drivers/scsi/arm/fas216.c: In function  fas216_kick :
drivers/scsi/arm/fas216.c:1959:3: warning: this statement may fall through [-Wimplicit-fallthrough=]
   fas216_allocate_tag(info, SCpnt);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/scsi/arm/fas216.c:1960:2: note: here
  case TYPE_OTHER:
  ^~~~
drivers/scsi/arm/fas216.c: In function  fas216_busservice_intr :
drivers/scsi/arm/fas216.c:1413:3: warning: this statement may fall through [-Wimplicit-fallthrough=]
   fas216_stoptransfer(info);
   ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/scsi/arm/fas216.c:1414:2: note: here
  case STATE(STAT_STATUS, PHASE_SELSTEPS):/* Sel w/ steps -> Status       */
  ^~~~
drivers/scsi/arm/fas216.c:1424:3: warning: this statement may fall through [-Wimplicit-fallthrough=]
   fas216_stoptransfer(info);
   ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/scsi/arm/fas216.c:1425:2: note: here
  case STATE(STAT_MESGIN, PHASE_COMMAND): /* Command -> Message In */
  ^~~~
drivers/scsi/arm/fas216.c: In function  fas216_funcdone_intr :
drivers/scsi/arm/fas216.c:1573:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
   if ((stat & STAT_BUSMASK) == STAT_MESGIN) {
      ^
drivers/scsi/arm/fas216.c:1579:2: note: here
  default:
  ^~~~~~~
drivers/scsi/arm/fas216.c: In function  fas216_handlesync :
drivers/scsi/arm/fas216.c:605:20: warning: this statement may fall through [-Wimplicit-fallthrough=]
   info->scsi.phase = PHASE_MSGOUT_EXPECT;
   ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
drivers/scsi/arm/fas216.c:607:2: note: here
  case async:
  ^~~~

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: megaraid_sas: Introduce module parameter for default queue depth
Chandrakanth Patil [Fri, 26 Jul 2019 07:32:14 +0000 (13:02 +0530)]
scsi: megaraid_sas: Introduce module parameter for default 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 value
suggested by firmware (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 value reported by
firmware. The module parameter can provide an interface for one time grub
settings and provides persistent settings across the boot.

[mkp: tweaked commit desc]

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Chandrakanth Patil <chandrakanth.patil@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Fix a NULL pointer dereference
Bart Van Assche [Fri, 9 Aug 2019 03:02:19 +0000 (20:02 -0700)]
scsi: qla2xxx: Fix a NULL pointer dereference

BUG: KASAN: null-ptr-deref in qla24xx_handle_plogi_done_event+0x134/0x9f0 [qla2xxx]
Read of size 4 at addr 00000000000000a0 by task swapper/2/0

CPU: 2 PID: 0 Comm: swapper/2 Not tainted 5.2.0-dbg+ #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
 <IRQ>
 dump_stack+0x8a/0xd6
 __kasan_report.cold+0x5/0x41
 kasan_report+0x16/0x20
 __asan_load4+0x7e/0x80
 qla24xx_handle_plogi_done_event+0x134/0x9f0 [qla2xxx]
 qla2x00_els_dcmd2_sp_done+0x15f/0x230 [qla2xxx]
 qla24xx_els_ct_entry+0x3b3/0x610 [qla2xxx]
 qla24xx_process_response_queue+0x514/0x10e0 [qla2xxx]
 qla24xx_msix_rsp_q+0x80/0x100 [qla2xxx]
 __handle_irq_event_percpu+0x72/0x450
 handle_irq_event_percpu+0x74/0xf0
 handle_irq_event+0x5e/0x8f
 handle_edge_irq+0x13a/0x320
 handle_irq+0x30/0x40
 do_IRQ+0x91/0x190
 common_interrupt+0xf/0xf
 </IRQ>
RIP: 0010:default_idle+0x31/0x230

Fixes: 8777e4314d39 ("scsi: qla2xxx: Migrate NVME N2N handling into state machine") # v4.19.
Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Simplify qla24xx_async_abort_cmd()
Bart Van Assche [Fri, 9 Aug 2019 03:02:18 +0000 (20:02 -0700)]
scsi: qla2xxx: Simplify qla24xx_async_abort_cmd()

Make the code easier to read by converting 'goto' statements into
'return' statements.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Remove two superfluous if-tests
Bart Van Assche [Fri, 9 Aug 2019 03:02:17 +0000 (20:02 -0700)]
scsi: qla2xxx: Remove two superfluous if-tests

This patch fixes the following Coverity complaint:

Null-checking sp->u.iocb_cmd.u.ctarg.rsp suggests that it may be null, but
it has already been dereferenced on all paths leading to the check.

See also commit e374f9f59281 ("scsi: qla2xxx: Migrate switch registration commands away from mailbox interface") # v4.16.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Introduce qla2x00_els_dcmd2_free()
Bart Van Assche [Fri, 9 Aug 2019 03:02:16 +0000 (20:02 -0700)]
scsi: qla2xxx: Introduce qla2x00_els_dcmd2_free()

This patch reduces code duplication.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Inline the qla2x00_fcport_event_handler() function
Bart Van Assche [Fri, 9 Aug 2019 03:02:15 +0000 (20:02 -0700)]
scsi: qla2xxx: Inline the qla2x00_fcport_event_handler() function

Instead of calling qla2x00_fcport_event_handler() and letting the switch
statement inside that function decide which other function to call, call
the latter function directly. Remove the event member from the event_arg
structure because it is no longer needed. Remove the
qla_handle_els_plogi_done() function because it is never called.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Report invalid mailbox status codes
Bart Van Assche [Fri, 9 Aug 2019 03:02:14 +0000 (20:02 -0700)]
scsi: qla2xxx: Report invalid mailbox status codes

It is easy to mix up the QLA_* and the MBS_* status codes. Complain loudly
if that happens.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Remove superfluous sts_entry_* casts
Bart Van Assche [Fri, 9 Aug 2019 03:02:13 +0000 (20:02 -0700)]
scsi: qla2xxx: Remove superfluous sts_entry_* casts

The C language supports implicit casting of void pointers to non-void
pointers. Remove explicit sts_entry_* casts that are not necessary.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Let the compiler check the type of the SCSI command context pointer
Bart Van Assche [Fri, 9 Aug 2019 03:02:12 +0000 (20:02 -0700)]
scsi: qla2xxx: Let the compiler check the type of the SCSI command context pointer

Split srb_cmd.ctx into two pointers such that the compiler can check the
type of that pointer.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Complain if sp->done() is not called from the completion path
Bart Van Assche [Fri, 9 Aug 2019 03:02:11 +0000 (20:02 -0700)]
scsi: qla2xxx: Complain if sp->done() is not called from the completion path

Not calling sp->done() from the command completion path is a severe bug.
Hence complain loudly if that happens.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Make sure that aborted commands are freed
Bart Van Assche [Fri, 9 Aug 2019 03:02:10 +0000 (20:02 -0700)]
scsi: qla2xxx: Make sure that aborted commands are freed

The LIO core requires that the target driver callback functions
.queue_data_in() and .queue_status() call target_put_sess_cmd() or
transport_generic_free_cmd(). These calls may happen synchronously or
asynchronously. Make sure that one of these LIO functions is called in case
a command has been aborted. This patch avoids that the code for removing a
session hangs due to commands that do not make progress.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Fixes: 694833ee00c4 ("scsi: tcm_qla2xxx: Do not allow aborted cmd to advance.") # v4.13.
Fixes: a07100e00ac4 ("qla2xxx: Fix TMR ABORT interaction issue between qla2xxx and TCM") # v4.5.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Introduce qla2xxx_get_next_handle()
Bart Van Assche [Fri, 9 Aug 2019 03:02:09 +0000 (20:02 -0700)]
scsi: qla2xxx: Introduce qla2xxx_get_next_handle()

This patch reduces code duplication.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Modify NVMe include directives
Bart Van Assche [Fri, 9 Aug 2019 03:02:08 +0000 (20:02 -0700)]
scsi: qla2xxx: Modify NVMe include directives

Since struct sg_table is used in nvme-fc-driver.h, include
<linux/scatterlist.h> from that header file.

Since no definitions or declarations from <linux/blk-mq.h> are used in the
qla_nvme.h header file, do not include <linux/blk-mq.h> from that header
file.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Make qlt_handle_abts_completion() more robust
Bart Van Assche [Fri, 9 Aug 2019 03:02:07 +0000 (20:02 -0700)]
scsi: qla2xxx: Make qlt_handle_abts_completion() more robust

Avoid that this function crashes if mcmd == NULL.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Fix a race condition between aborting and completing a SCSI command
Bart Van Assche [Fri, 9 Aug 2019 03:02:06 +0000 (20:02 -0700)]
scsi: qla2xxx: Fix a race condition between aborting and completing a SCSI command

Instead of allocating a struct srb dynamically from inside .queuecommand(),
set qla2xxx_driver_template.cmd_size such that struct scsi_cmnd and struct
srb are contiguous. Do not call QLA_QPAIR_MARK_BUSY() /
QLA_QPAIR_MARK_NOT_BUSY() for SRBs associated with SCSI commands. That is
safe because scsi_remove_host() is called before queue pairs are deleted
and scsi_remove_host() waits for all outstanding SCSI commands to finish.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Introduce the function qla2xxx_init_sp()
Bart Van Assche [Fri, 9 Aug 2019 03:02:05 +0000 (20:02 -0700)]
scsi: qla2xxx: Introduce the function qla2xxx_init_sp()

This patch does not change any functionality but makes the next patch
easier to read.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Enable type checking for the SRB free and done callback functions
Bart Van Assche [Fri, 9 Aug 2019 03:02:04 +0000 (20:02 -0700)]
scsi: qla2xxx: Enable type checking for the SRB free and done callback functions

Since all pointers passed to the srb_t.done() and srb_t.free() functions
have type srb_t, change the type of the first argument of these functions
from void * into struct srb *. This allows the compiler to verify the
argument types for these functions. This patch does not change any
functionality.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Rework key encoding in qlt_find_host_by_d_id()
Bart Van Assche [Fri, 9 Aug 2019 03:02:03 +0000 (20:02 -0700)]
scsi: qla2xxx: Rework key encoding in qlt_find_host_by_d_id()

Use the same approach for encoding the destination ID as the approach used
by qlt_update_vp_map().

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Set the responder mode if appropriate for ELS pass-through IOCBs
Bart Van Assche [Fri, 9 Aug 2019 03:02:02 +0000 (20:02 -0700)]
scsi: qla2xxx: Set the responder mode if appropriate for ELS pass-through IOCBs

According to the firmware documentation responder mode must be set for ELS
pass-through IOCBs if a response is expected.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Make it explicit that ELS pass-through IOCBs use little endian
Bart Van Assche [Fri, 9 Aug 2019 03:02:01 +0000 (20:02 -0700)]
scsi: qla2xxx: Make it explicit that ELS pass-through IOCBs use little endian

According to the firmware documentation the firmware expects all ELS
pass-through IOCB parameters in little endian format. Make this explicit.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Check secondary image if reading the primary image fails
Bart Van Assche [Fri, 9 Aug 2019 03:02:00 +0000 (20:02 -0700)]
scsi: qla2xxx: Check secondary image if reading the primary image fails

This patch fixes several Coverity complaints about reading data that has
not been initialized.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Change the return type of qla24xx_read_flash_data()
Bart Van Assche [Fri, 9 Aug 2019 03:01:59 +0000 (20:01 -0700)]
scsi: qla2xxx: Change the return type of qla24xx_read_flash_data()

This change makes it easier to detect qla24xx_read_flash_data() failures
and also to handle such failures. This change does not modify the behavior
of the driver since all callers ignore the qla24xx_read_flash_data()
return value.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Introduce the be_id_t and le_id_t data types for FC src/dst IDs
Bart Van Assche [Fri, 9 Aug 2019 03:01:58 +0000 (20:01 -0700)]
scsi: qla2xxx: Introduce the be_id_t and le_id_t data types for FC src/dst IDs

Introduce the be_id_t and le_id_t data types for Fibre Channel source and
destination ID formats supported by the firmware instead of using an
uint8_t[3] array. Introduce functions for converting from and to the
port_id_t data types. This patch does not change the behavior of the
qla2xxx driver but improves source code readability and also allows the
compiler to verify the endianness of Fibre Channel IDs.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Complain if a soft reset fails
Bart Van Assche [Fri, 9 Aug 2019 03:01:57 +0000 (20:01 -0700)]
scsi: qla2xxx: Complain if a soft reset fails

Failure of a soft reset is a severe failure. Hence report such failures.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Use memcpy() and strlcpy() instead of strcpy() and strncpy()
Bart Van Assche [Fri, 9 Aug 2019 03:01:56 +0000 (20:01 -0700)]
scsi: qla2xxx: Use memcpy() and strlcpy() instead of strcpy() and strncpy()

This patch makes the string manipulation code easier to verify.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Check the PCI info string output buffer size
Bart Van Assche [Fri, 9 Aug 2019 03:01:55 +0000 (20:01 -0700)]
scsi: qla2xxx: Check the PCI info string output buffer size

Pass the output buffer size to the code that generates a PCI info string
and check the output buffer size while generating a PCI info string.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Complain if waiting for pending commands times out
Bart Van Assche [Fri, 9 Aug 2019 03:01:54 +0000 (20:01 -0700)]
scsi: qla2xxx: Complain if waiting for pending commands times out

Such a timeout is a severe issue. Hence complain if waiting for pending
commands times out. This patch fixes a small bug: it modifies
qla82xx_chip_reset_cleanup() such that the "Done waiting" message is
reported if qla82xx_chip_reset_cleanup() succeeded instead of if that
function failed.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Declare fourth qla2x00_set_model_info() argument const
Bart Van Assche [Fri, 9 Aug 2019 03:01:53 +0000 (20:01 -0700)]
scsi: qla2xxx: Declare fourth qla2x00_set_model_info() argument const

Make it clear to humans and also to the compiler that the string passed
as fourth argument is not modified.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Always check the qla2x00_wait_for_hba_online() return value
Bart Van Assche [Fri, 9 Aug 2019 03:01:52 +0000 (20:01 -0700)]
scsi: qla2xxx: Always check the qla2x00_wait_for_hba_online() return value

This patch fixes several Coverity complaints about not always checking
the qla2x00_wait_for_hba_online() return value.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Suppress multiple Coverity complaint about out-of-bounds accesses
Bart Van Assche [Fri, 9 Aug 2019 03:01:51 +0000 (20:01 -0700)]
scsi: qla2xxx: Suppress multiple Coverity complaint about out-of-bounds accesses

This patch does not change any functionality.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Suppress a Coveritiy complaint about integer overflow
Bart Van Assche [Fri, 9 Aug 2019 03:01:50 +0000 (20:01 -0700)]
scsi: qla2xxx: Suppress a Coveritiy complaint about integer overflow

This patch fixes the following Coverity complaint:

Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
overflow_before_widen: Potentially overflowing expression dma_eng_num *
65536U with type unsigned int (32 bits, unsigned) is evaluated using 32-bit
arithmetic, and then used in a context that expects an expression of type
uint64_t (64 bits, unsigned).

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Remove unreachable code from qla83xx_idc_lock()
Bart Van Assche [Fri, 9 Aug 2019 03:01:49 +0000 (20:01 -0700)]
scsi: qla2xxx: Remove unreachable code from qla83xx_idc_lock()

This was detected by Coverity.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Fix qla24xx_process_bidir_cmd()
Bart Van Assche [Fri, 9 Aug 2019 03:01:48 +0000 (20:01 -0700)]
scsi: qla2xxx: Fix qla24xx_process_bidir_cmd()

Set the r??_data_len variables before using these instead of after.

This patch fixes the following Coverity complaint:

const: At condition req_data_len != rsp_data_len, the value of req_data_len
must be equal to 0.
const: At condition req_data_len != rsp_data_len, the value of rsp_data_len
must be equal to 0.
dead_error_condition: The condition req_data_len != rsp_data_len cannot be
true.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Fixes: a9b6f722f62d ("[SCSI] qla2xxx: Implementation of bidirectional.") # v3.7.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Simplify a debug statement
Bart Van Assche [Fri, 9 Aug 2019 03:01:47 +0000 (20:01 -0700)]
scsi: qla2xxx: Simplify a debug statement

Read the FC port state once instead of twice. This patch fixes the
following Coverity complaint:

Unchecked return value (CHECKED_RETURN)
check_return: Calling atomic_read without checking return value (as is
done elsewhere 80 out of 92 times).

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Remove dead code
Bart Van Assche [Fri, 9 Aug 2019 03:01:46 +0000 (20:01 -0700)]
scsi: qla2xxx: Remove dead code

Since sess == NULL before 'goto out_term2' is executed, the code under 'if
(sess)' cannot be reached. Hence remove that code. This was detected by
Coverity.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Complain if parsing the version string fails
Bart Van Assche [Fri, 9 Aug 2019 03:01:45 +0000 (20:01 -0700)]
scsi: qla2xxx: Complain if parsing the version string fails

This patch fixes a Coverity complaint about not checking the sscanf()
return value.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Complain if a mailbox command times out
Bart Van Assche [Fri, 9 Aug 2019 03:01:44 +0000 (20:01 -0700)]
scsi: qla2xxx: Complain if a mailbox command times out

This patch fixes the following Coverity complaint:

Unchecked return value (CHECKED_RETURN)
check_return: Calling wait_for_completion_timeout without checking return
value (as is done elsewhere 14 out of 17 times).

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Use strlcpy() instead of strncpy()
Bart Van Assche [Fri, 9 Aug 2019 03:01:43 +0000 (20:01 -0700)]
scsi: qla2xxx: Use strlcpy() instead of strncpy()

This patch fixes several gcc complaints about string truncation.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Do not corrupt vha->plogi_ack_list
Bart Van Assche [Fri, 9 Aug 2019 03:01:42 +0000 (20:01 -0700)]
scsi: qla2xxx: Do not corrupt vha->plogi_ack_list

Delete the PLOGIN ACK data structure from the vha->plogi_ack_list before
freeing that data structure to avoid that that list gets corrupted.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Report the firmware status code if a mailbox command fails
Bart Van Assche [Fri, 9 Aug 2019 03:01:41 +0000 (20:01 -0700)]
scsi: qla2xxx: Report the firmware status code if a mailbox command fails

It is helpful when debugging this driver to have the firmware status code
available if a mailbox command fails. Hence report that firmware status
code.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Fix session lookup in qlt_abort_work()
Bart Van Assche [Fri, 9 Aug 2019 03:01:40 +0000 (20:01 -0700)]
scsi: qla2xxx: Fix session lookup in qlt_abort_work()

Pass the correct session ID to find_sess_by_s_id() instead of passing an
uninitialized variable.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Fixes: 2d70c103fd2a ("[SCSI] qla2xxx: Add LLD target-mode infrastructure for >= 24xx series") # v3.5.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Simplify qla24xx_abort_sp_done()
Bart Van Assche [Fri, 9 Aug 2019 03:01:39 +0000 (20:01 -0700)]
scsi: qla2xxx: Simplify qla24xx_abort_sp_done()

Instead of explicitly checking whether a timeout has occurred, ignore the
del_timer() return value.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Remove two superfluous tests
Bart Van Assche [Fri, 9 Aug 2019 03:01:38 +0000 (20:01 -0700)]
scsi: qla2xxx: Remove two superfluous tests

Since qlt_remove_target() only calls qlt_release() if
vha->vha_tgt.qla_tgt != NULL, checking that pointer inside qlt_release()
is not necessary. This patch fixes the following Coverity complaint:

CID 188348 (#1 of 1): Dereference after null check (FORWARD_NULL)
var_deref_model: Passing null pointer &vha->vha_tgt.qla_tgt->tgt_list_entry
to list_del, which dereferences it.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Remove a superfluous pointer check
Bart Van Assche [Fri, 9 Aug 2019 03:01:37 +0000 (20:01 -0700)]
scsi: qla2xxx: Remove a superfluous pointer check

Checking a pointer after it has been dereferenced is not useful. This was
detected by Coverity.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Simplify qlt_lport_dump()
Bart Van Assche [Fri, 9 Aug 2019 03:01:36 +0000 (20:01 -0700)]
scsi: qla2xxx: Simplify qlt_lport_dump()

Simplify the implementation of this function by using the %phC format
specifier instead of using explicit for-loops.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Reduce the number of casts in GID list code
Bart Van Assche [Fri, 9 Aug 2019 03:01:35 +0000 (20:01 -0700)]
scsi: qla2xxx: Reduce the number of casts in GID list code

This patch makes the code that parses the GID list easier to read without
changing the behavior of the code.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Verify locking assumptions at runtime
Bart Van Assche [Fri, 9 Aug 2019 03:01:34 +0000 (20:01 -0700)]
scsi: qla2xxx: Verify locking assumptions at runtime

Make sure that locking assumptions are verified at runtime if kernel
debugging is enabled.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Change data_dsd into an array
Bart Van Assche [Fri, 9 Aug 2019 03:01:33 +0000 (20:01 -0700)]
scsi: qla2xxx: Change data_dsd into an array

This patch does not change any functionality but fixes a Coverity complaint
about using a scalar as an array.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Declare qla_tgt_cmd.cdb const
Bart Van Assche [Fri, 9 Aug 2019 03:01:32 +0000 (20:01 -0700)]
scsi: qla2xxx: Declare qla_tgt_cmd.cdb const

Make it clear that the CDB is not modified after processing of a SCSI
command has started.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Reduce the scope of three local variables in qla2xxx_queuecommand()
Bart Van Assche [Fri, 9 Aug 2019 03:01:31 +0000 (20:01 -0700)]
scsi: qla2xxx: Reduce the scope of three local variables in qla2xxx_queuecommand()

This patch makes it clear that the tag, hwq and qpair variables are only
used in the mq path.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Change the return type of qla2x00_update_ms_fdmi_iocb() into void
Bart Van Assche [Fri, 9 Aug 2019 03:01:30 +0000 (20:01 -0700)]
scsi: qla2xxx: Change the return type of qla2x00_update_ms_fdmi_iocb() into void

The value returned by this function is not used. Hence change the return
type of this function into 'void' and remove the return statement.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Declare the fourth ql_dump_buffer() argument const
Bart Van Assche [Fri, 9 Aug 2019 03:01:29 +0000 (20:01 -0700)]
scsi: qla2xxx: Declare the fourth ql_dump_buffer() argument const

This patch makes it clear to humans and also to the compiler that
ql_dump_buffer() does not modify the memory the @buf argument points at.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Remove a superfluous forward declaration
Bart Van Assche [Fri, 9 Aug 2019 03:01:28 +0000 (20:01 -0700)]
scsi: qla2xxx: Remove a superfluous forward declaration

Since qlt_make_local_sess() is defined before it is called, remove the
forward declaration of that function.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Remove an include directive from qla_mr.c
Bart Van Assche [Fri, 9 Aug 2019 03:01:27 +0000 (20:01 -0700)]
scsi: qla2xxx: Remove an include directive from qla_mr.c

There is no bsg code in the qla_mr.c source file. Hence do not include
the <linux/bsg-lib.h> header file from qla_mr.c.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Include the <asm/unaligned.h> header file from qla_dsd.h
Bart Van Assche [Fri, 9 Aug 2019 03:01:26 +0000 (20:01 -0700)]
scsi: qla2xxx: Include the <asm/unaligned.h> header file from qla_dsd.h

Since the put_unaligned_*() macros are used in this header file, include
the header file that defines these macros.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Fixes: 15b7a68c1d03 ("scsi: qla2xxx: Introduce the dsd32 and dsd64 data structures") # v5.2-rc1.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Use tabs instead of spaces for indentation
Bart Van Assche [Fri, 9 Aug 2019 03:01:25 +0000 (20:01 -0700)]
scsi: qla2xxx: Use tabs instead of spaces for indentation

This patch only modifies whitespace.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Improve Linux kernel coding style conformance
Bart Van Assche [Fri, 9 Aug 2019 03:01:24 +0000 (20:01 -0700)]
scsi: qla2xxx: Improve Linux kernel coding style conformance

Insert a space where required, surround complex expressions in macros with
parentheses, use the UL suffix instead of the (unsigned long) cast, do not
use line continuations when not necessary and do not explicitly initialize
static variables to zero.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Really fix qla2xxx_eh_abort()
Bart Van Assche [Fri, 9 Aug 2019 03:01:23 +0000 (20:01 -0700)]
scsi: qla2xxx: Really fix qla2xxx_eh_abort()

I'm not sure how this happened but the patch that was intended to fix abort
handling was incomplete. This patch fixes that patch as follows:

 - If aborting the SCSI command failed, wait until the SCSI command
   completes.

 - Return SUCCESS instead of FAILED if an abort attempt races with SCSI
   command completion.

 - Since qla2xxx_eh_abort() increments the sp reference count by calling
   sp_get(), decrement the sp reference count before returning.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Fixes: 219d27d7147e ("scsi: qla2xxx: Fix race conditions in the code for aborting SCSI commands")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: qla2xxx: Make qla2x00_abort_srb() again decrease the sp reference count
Bart Van Assche [Fri, 9 Aug 2019 03:01:22 +0000 (20:01 -0700)]
scsi: qla2xxx: Make qla2x00_abort_srb() again decrease the sp reference count

Since qla2x00_abort_srb() starts with increasing the reference count of
@sp, decrease that same reference count before returning.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Fixes: 219d27d7147e ("scsi: qla2xxx: Fix race conditions in the code for aborting SCSI commands") # v5.2.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: mpt3sas: Update driver version to 31.100.00.00
Suganath Prabu [Sat, 3 Aug 2019 13:59:57 +0000 (09:59 -0400)]
scsi: mpt3sas: Update driver version to 31.100.00.00

Updated driver version from 29.100.00.00 to 31.100.00.00 which is
equivalent to Phase 12 OOB.

Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: mpt3sas: Run SAS DEVICE STATUS CHANGE EVENT from ISR
Suganath Prabu [Sat, 3 Aug 2019 13:59:56 +0000 (09:59 -0400)]
scsi: mpt3sas: Run SAS DEVICE STATUS CHANGE EVENT from ISR

In some cases, like while performing extensive expander reset or phy reset,
user may observe that drives are not visible in OS. Driver's
firmware-worker thread is blocked for more than 120 seconds resulting in a
call trace.

1. Received target add event for Device A and hence driver has registered
this device to SML by calling sas_rphy_add(). SML has half added this
device and returned the control to the driver by quitting from
sas_rphy_add() API, and started some background scanning on this device A.

2. While background scanning is going on device A, driver has received SAS
DEVICE STATUS CHANGE EVENT with RC code "Internal device reset" event and
hence driver has set tm_busy flag for this Device A from FW worker thread
context. When tm_busy flag is set then driver return scsi commands with
device busy status asking the kernel to retry the command after some time.
So background scanning for device A will be waiting for this tm_busy to be
cleared.

3. Meanwhile driver has received a target add event for Device B and hence
driver called sas_rphy_add() API to register this device with SML. But
since background scanning for Device A is still pending and SML is not
quitting from sas_rphy_add(), the driver’s firmware worker thread got
blocked.

4. Now driver has received SAS DEVICE STATUS CHANGE EVENT with RC code
"Internal device reset complete" event. But as driver’s firmware worker
thread got blocked in Step3, it can’t process this event and it was not
clearing the tm_busy flag and deadlock occurred (where SML was waiting for
tm_busy flag to be cleared and our FW worker thread is waiting for SML to
quit from sas_device_rphy_add() API).

Same deadlock will be observed even if device B is getting removed in
step3. So to limit these types of deadlocks driver will process the SAS
DEVICE STATUS CHANGE EVENT events from ISR context instead of processing
this event from worker thread context.  This improvement avoids above
deadlock.

Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: mpt3sas: Reduce the performance drop
Suganath Prabu [Sat, 3 Aug 2019 13:59:55 +0000 (09:59 -0400)]
scsi: mpt3sas: Reduce the performance drop

This patch is to reduce the performance drop depth observed on SATA HDD
when ATA PT command is outstanding.

Driver returns IO commands with status "SAM_STAT_BUSY" whenever ATA PT
command is outstanding. With this, IO commands will be retried until this
outstanding ATA PT to complete and hence we will observe drop in
performance.

As the driver is completing the subsequent IOs commands with SAM_STAT_BUSY
status, these IOs has to go though the block layer.  Hence it adds latency
to the IOs and large performance drop is observed.

So to reduce this performance dropp, added improvement in driver to return
the subsequent IOs with SCSI_MLQUEUE_DEVICE_BUSY status instead of
completing the IOs with SAM_STAT_BUSY status when ATA PT command is
outstanding. Sending command back with SCSI_MLQUEUE_DEVICE_BUSY does not go
through complete block layer stack (as scsi_done won't be called) SML will
immediately retry the command and this method will avoid latency of block
layer stack and the performance impact will be reduced.

On Local setup, ran 512k sequential read IO operation on HGST SATA drive
with existing driver & with this improvement drivers and here is the
result,

1. With existing driver: IOs are running at bandwidth of ~230 rMB/s and
whenever any ATA PT command is outstanding (e.g issued from systemd-udevd
daemon) then this bandwidth drops to ~150 rMB/s.

2. With this improvement driver: IOs are running at bandwidth of ~230 rMB/s
and whenever any ATA PT command is outstanding then this bandwidth drops to
just ~190 rMB/s.

Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: mpt3sas: Handle fault during HBA initialization
Suganath Prabu [Sat, 3 Aug 2019 13:59:54 +0000 (09:59 -0400)]
scsi: mpt3sas: Handle fault during HBA initialization

During HBA initialization time, if handshake operation fails due to some
firmware fault then currently driver is terminating the HBA
initialization. It is possible that HBA may come up properly if diag reset
is issued.

So improvement is made in driver in such a way that before terminating the
HBA initialization, driver checks the IOC state and if IOC state is in
fault state then issue diag reset for once. If diag reset is successful
then continue with HBA initialization else terminate the HBA
initialization.

Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: mpt3sas: Add sysfs to know supported features
Suganath Prabu [Sat, 3 Aug 2019 13:59:53 +0000 (09:59 -0400)]
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>
4 years agoscsi: mpt3sas: Support MEMORY MOVE Tool box command
Suganath Prabu [Sat, 3 Aug 2019 13:59:52 +0000 (09:59 -0400)]
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>
4 years agoscsi: mpt3sas: Allow ioctls to blocked access status NVMe
Suganath Prabu [Sat, 3 Aug 2019 13:59:51 +0000 (09:59 -0400)]
scsi: mpt3sas: Allow ioctls to blocked access status NVMe

If driver sees the NVMe drive with "DEVICE_BLOCKED" AccessStatus in its
PCIe Device Page0, then driver removes the drive from its internal list and
does not allow any IOCTL commands to be sent to the drive and will return
the IOCTLs with "-ENODEV" status.

The driver will now allow NVMe Encapsulated IOCTL issued to the NVMe device
with an access status of DEVICE_BLOCKED. This change allows the user to
flash new drive firmware online and revive the drive.

Add NVMe device only the driver's internal list even though the device is
in the blocked state so that the device will be visible to Apps. This way
Apps can send NVMe Encapsulated IOCTLs to this drive and bring the drive
online. This NVMe drive with DEVICE_BLOCKED access status won't added to
the SML, it will be added only in the driver's internal list.

[mkp: clarified desc]

Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: mpt3sas: Enumerate SES of a managed PCIe switch
Suganath Prabu [Sat, 3 Aug 2019 13:59:50 +0000 (09:59 -0400)]
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>
4 years agoscsi: mpt3sas: Update MPI headers to 2.6.8 spec
Suganath Prabu [Sat, 3 Aug 2019 13:59:49 +0000 (09:59 -0400)]
scsi: mpt3sas: Update MPI headers to 2.6.8 spec

Updated MPI to 2.6.8 specification and header files to 2.00.54.

Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: mpt3sas: Gracefully handle online firmware update
Suganath Prabu [Sat, 3 Aug 2019 13:59:48 +0000 (09:59 -0400)]
scsi: mpt3sas: Gracefully handle online firmware update

Issue:

During online Firmware upgrade operations it is possible that MaxDevHandles
filled in IOCFacts may change with new FW.  With this we may observe kernel
panics when driver try to access the pd_handles or blocking_handles buffers
at offset greater than the old firmware's MaxDevHandle value.

Fix:

_base_check_ioc_facts_changes() looks for increase/decrease in IOCFacts
attributes during online firmware upgrade and increases the pd_handles,
blocking_handles, etc buffer sizes to new firmware's MaxDevHandle value if
this new firmware's MaxDevHandle value is greater than the old firmware's
MaxDevHandle value.

Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: mpt3sas: memset request frame before reusing
Suganath Prabu [Sat, 3 Aug 2019 13:59:47 +0000 (09:59 -0400)]
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>
4 years agoscsi: mpt3sas: Add support for PCIe Lane margin
Suganath Prabu [Sat, 3 Aug 2019 13:59:46 +0000 (09:59 -0400)]
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>
4 years agoscsi: pm80xx: remove redundant assignments to variable rc
Colin Ian King [Wed, 31 Jul 2019 22:22:14 +0000 (23:22 +0100)]
scsi: pm80xx: remove redundant assignments to variable rc

There are several occasions where variable rc is being initialized with a
value that is never read and error is being re-assigned a little later on.
Clean up the code by removing rc entirely and just returning the return
value from the call to pm8001_issue_ssp_tmf

Addresses-Coverity: ("Unused value")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: hisi_sas: Consolidate internal abort calls in LU reset operation
Luo Jiaxing [Mon, 5 Aug 2019 13:48:12 +0000 (21:48 +0800)]
scsi: hisi_sas: Consolidate internal abort calls in LU reset operation

In hisi_sas_lu_reset(), we call internal abort for SAS and SATA device
codepaths -> consolidate into a single call.

Signed-off-by: Luo Jiaxing <luojiaxing@huawei.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: hisi_sas: replace "%p" with "%pK"
Xiang Chen [Mon, 5 Aug 2019 13:48:11 +0000 (21:48 +0800)]
scsi: hisi_sas: replace "%p" with "%pK"

The format specifier "%p" can leak kernel address, and use "%pK" instead.

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>
4 years agoscsi: hisi_sas: Remove some unnecessary code
Xiang Chen [Mon, 5 Aug 2019 13:48:10 +0000 (21:48 +0800)]
scsi: hisi_sas: Remove some unnecessary code

Remove some unnecessary code, including:

 - Explicit zeroing of memory allocated for dmam_alloc_coherent()

 - Some duplicated code

 - Some redundant masking

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>
4 years agoscsi: hisi_sas: Modify return type of debugfs functions
Luo Jiaxing [Mon, 5 Aug 2019 13:48:09 +0000 (21:48 +0800)]
scsi: hisi_sas: Modify return type of debugfs functions

For functions which always return 0, which is never checked, make to return
void.

Signed-off-by: Luo Jiaxing <luojiaxing@huawei.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
4 years agoscsi: hisi_sas: Drop free_irq() when devm_request_irq() failed
Xiang Chen [Mon, 5 Aug 2019 13:48:08 +0000 (21:48 +0800)]
scsi: hisi_sas: Drop free_irq() when devm_request_irq() failed

It will free irq automatically if devm_request_irq() failed, so drop
free_irq() if devm_request_irq() failed.

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>
4 years agoscsi: hisi_sas: Drop SMP resp frame DMA mapping
John Garry [Mon, 5 Aug 2019 13:48:07 +0000 (21:48 +0800)]
scsi: hisi_sas: Drop SMP resp frame DMA mapping

The SMP frame response is written to the command table and not the SMP
response pointer from libsas, so don't bother DMA mapping (and unmapping)
the SMP response from libsas.

Suggested-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>