linux-2.6-block.git
8 months agoscsi: message: fusion: Initialize return value in mptfc_bus_reset()
Hannes Reinecke [Mon, 23 Oct 2023 07:30:05 +0000 (09:30 +0200)]
scsi: message: fusion: Initialize return value in mptfc_bus_reset()

Detected by smatch.

Fixes: 17865dc2eccc ("scsi: message: fusion: Open-code mptfc_block_error_handler() for bus reset")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231023073005.20766-1-hare@suse.de
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: mpt3sas: Fix loop logic
Ranjan Kumar [Fri, 20 Oct 2023 10:58:49 +0000 (16:28 +0530)]
scsi: mpt3sas: Fix loop logic

The retry loop continues to iterate until the count reaches 30, even after
receiving the correct value. Exit loop when a non-zero value is read.

Fixes: 4ca10f3e3174 ("scsi: mpt3sas: Perform additional retries if doorbell read returns 0")
Cc: stable@vger.kernel.org
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
Link: https://lore.kernel.org/r/20231020105849.6350-1-ranjan.kumar@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: snic: Remove useless code in snic_dr_clean_pending_req()
Su Hui [Fri, 20 Oct 2023 02:33:27 +0000 (10:33 +0800)]
scsi: snic: Remove useless code in snic_dr_clean_pending_req()

Return error code directly to save space and be more clear.

Signed-off-by: Su Hui <suhui@nfschina.com>
Link: https://lore.kernel.org/r/20231020023326.43898-1-suhui@nfschina.com
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: core: Add comment to target_destroy in scsi_host_template
Wenchao Hao [Wed, 18 Oct 2023 11:37:46 +0000 (19:37 +0800)]
scsi: core: Add comment to target_destroy in scsi_host_template

Add comment to indicate that the callback function target_destroy in the
scsi_host_template must not sleep.

Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Link: https://lore.kernel.org/r/20231018113746.1940197-3-haowenchao2@huawei.com
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: core: Clean up scsi_dev_queue_ready()
Wenchao Hao [Wed, 18 Oct 2023 11:37:45 +0000 (19:37 +0800)]
scsi: core: Clean up scsi_dev_queue_ready()

This is just a cleanup for scsi_dev_queue_ready() to avoid a redundant goto
and if statement. No functional change.

Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Link: https://lore.kernel.org/r/20231018113746.1940197-2-haowenchao2@huawei.com
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: pmcraid: Add missing scsi_device_put() in pmcraid_eh_target_reset_handler()
Hannes Reinecke [Mon, 23 Oct 2023 07:29:57 +0000 (09:29 +0200)]
scsi: pmcraid: Add missing scsi_device_put() in pmcraid_eh_target_reset_handler()

When breaking out of an shost_for_each_device() loop one needs to do an
explicit scsi_device_put().

Fixes: c2a14ab3b9b3 ("scsi: pmcraid: Select device in pmcraid_eh_target_reset_handler()")
Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231023072957.20191-1-hare@suse.de
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: target: core: Fix kernel-doc comment
Yang Li [Tue, 17 Oct 2023 03:09:13 +0000 (11:09 +0800)]
scsi: target: core: Fix kernel-doc comment

Fix kernel-doc comment to silence the warnings:

drivers/target/target_core_transport.c:1930: warning: Excess function parameter 'cmd' description in 'target_submit'
drivers/target/target_core_transport.c:1930: warning: Function parameter or member 'se_cmd' not described in 'target_submit'

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=6844
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
Link: https://lore.kernel.org/r/20231017030913.89973-1-yang.lee@linux.alibaba.com
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: pmcraid: Fix kernel-doc comment
Yang Li [Tue, 17 Oct 2023 02:58:53 +0000 (10:58 +0800)]
scsi: pmcraid: Fix kernel-doc comment

Fix kernel-doc comment to silence the warnings:

drivers/scsi/pmcraid.c:2697: warning: Excess function parameter 'scsi_cmd' description in 'pmcraid_reset_device'
drivers/scsi/pmcraid.c:2697: warning: Function parameter or member 'scsi_dev' not described in 'pmcraid_reset_device'

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=6843
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
Link: https://lore.kernel.org/r/20231017025853.67562-1-yang.lee@linux.alibaba.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: core: Handle depopulation and restoration in progress
Douglas Gilbert [Sun, 15 Oct 2023 05:06:50 +0000 (01:06 -0400)]
scsi: core: Handle depopulation and restoration in progress

The default handling of the NOT READY sense key is to wait for the device
to become ready. The "wait" is assumed to be relatively short. However
there is a sub-class of NOT READY that have the "... in progress" phrase in
their additional sense code and these can take much longer.  Following on
from commit 505aa4b6a883 ("scsi: sd: Defer spinning up drive while SANITIZE
is in progress") we now have element depopulation and restoration that can
take a long time.  For example, over 24 hours for a 20 TB, 7200 rpm hard
disk to depopulate 1 of its 20 elements.

Add handling of ASC/ASCQ: 0x4,0x24 (depopulation in progress)
and ASC/ASCQ: 0x4,0x25 (depopulation restoration in progress)
to sd.c . The scsi_lib.c has incomplete handling of these
two messages, so complete it.

Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
Link: https://lore.kernel.org/r/20231015050650.131145-1-dgilbert@interlog.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: ufs: core: Add support for parsing OPP
Manivannan Sadhasivam [Thu, 12 Oct 2023 17:21:27 +0000 (22:51 +0530)]
scsi: ufs: core: Add support for parsing OPP

OPP framework can be used to scale the clocks along with other entities
such as regulators, performance state etc... So let's add support for
parsing OPP from devicetree. OPP support in devicetree is added through the
"operating-points-v2" property which accepts the OPP table defining clock
frequency, regulator voltage, power domain performance state etc...

Since the UFS controller requires multiple clocks to be controlled for
proper working, devm_pm_opp_set_config() has been used which supports
scaling multiple clocks through custom ufshcd_opp_config_clks() callback.

It should be noted that the OPP support is not compatible with the old
"freq-table-hz" property. So only one can be used at a time even though
the UFS core supports both.

Co-developed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Link: https://lore.kernel.org/r/20231012172129.65172-4-manivannan.sadhasivam@linaro.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: ufs: core: Add OPP support for scaling clocks and regulators
Manivannan Sadhasivam [Thu, 12 Oct 2023 17:21:26 +0000 (22:51 +0530)]
scsi: ufs: core: Add OPP support for scaling clocks and regulators

UFS core is only scaling the clocks during devfreq scaling and
initialization. But for an optimum power saving, regulators should also be
scaled along with the clocks.

So let's use the OPP framework which supports scaling clocks, regulators,
and performance state using OPP table defined in devicetree. For
accomodating the OPP support, the existing APIs (ufshcd_scale_clks,
ufshcd_is_devfreq_scaling_required and ufshcd_devfreq_scale) are modified
to accept "freq" as an argument which in turn used by the OPP helpers.

The OPP support is added along with the old freq-table based clock scaling
so that the existing platforms work as expected.

Co-developed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Link: https://lore.kernel.org/r/20231012172129.65172-3-manivannan.sadhasivam@linaro.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: ufs: dt-bindings: common: Add OPP table
Krzysztof Kozlowski [Thu, 12 Oct 2023 17:21:25 +0000 (22:51 +0530)]
scsi: ufs: dt-bindings: common: Add OPP table

Except scaling UFS and bus clocks, it's necessary to scale also the
voltages of regulators or power domain performance state levels.  Adding
Operating Performance Points table allows to adjust power domain
performance state, depending on the UFS clock speed.

OPPv2 deprecates previous property limited to clock scaling:
freq-table-hz.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Link: https://lore.kernel.org/r/20231012172129.65172-2-manivannan.sadhasivam@linaro.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoMerge patch series "scsi: scsi_debug: Add error injection for single device"
Martin K. Petersen [Tue, 17 Oct 2023 00:51:40 +0000 (20:51 -0400)]
Merge patch series "scsi: scsi_debug: Add error injection for single device"

Wenchao Hao <haowenchao2@huawei.com> says:

The original error injection mechanism was based on scsi_host which
could not inject fault for a single SCSI device.

This patchset provides the ability to inject errors for a single SCSI
device. Now we support inject timeout errors, queuecommand errors, and
hostbyte, driverbyte, statusbyte, and sense data for specific SCSI
Command. Two new error injection is defined to make abort command or
reset LUN failed.

Besides error injection for single device, this patchset add a new
interface to make reset target failed for each scsi_target.

The first two patch add a debugfs interface to add and inquiry single
device's error injection info; the third patch defined how to remove
an injection which has been added. The following 5 patches use the
injection info and generate the related error type. The last two just
add a new interface to make reset target failed and control
scsi_device's allow_restart flag.

Link: https://lore.kernel.org/r/20231010092051.608007-1-haowenchao2@huawei.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: scsi_debug: Add param to control sdev's allow_restart
Wenchao Hao [Tue, 10 Oct 2023 09:20:51 +0000 (17:20 +0800)]
scsi: scsi_debug: Add param to control sdev's allow_restart

Add new module param "allow_restart" to control scsi_device's allow_restart
flag. This flag determines if EH is triggered after a command completes
with sense_key 0x6, ASC 0x4 and ASCQ 0x2. EH would be triggered if
allow_restart=1 in this condition.

The new param can be used with the error injection capability to test how
commands completing with sense_key 0x6, ASC 0x4 and ASCQ 0x2 are handled.

Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Link: https://lore.kernel.org/r/20231010092051.608007-11-haowenchao2@huawei.com
Tested-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: scsi_debug: Add debugfs interface to fail target reset
Wenchao Hao [Tue, 10 Oct 2023 09:20:50 +0000 (17:20 +0800)]
scsi: scsi_debug: Add debugfs interface to fail target reset

The interface is found at
/sys/kernel/debug/scsi_debug/target<h:c:t>/fail_reset where <h:c:t>
identifies the target to inject errors on. It's a simple bool type
interface which would make this target's reset fail if set to 'Y'.

Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Link: https://lore.kernel.org/r/20231010092051.608007-10-haowenchao2@huawei.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: scsi_debug: Add new error injection type: Reset LUN failed
Wenchao Hao [Tue, 10 Oct 2023 09:20:49 +0000 (17:20 +0800)]
scsi: scsi_debug: Add new error injection type: Reset LUN failed

Add error injection type 4 to make scsi_debug_device_reset() return FAILED.
Fail abort command format:

  +--------+------+-------------------------------------------------------+
  | Column | Type | Description                                           |
  +--------+------+-------------------------------------------------------+
  |   1    |  u8  | Error type, fixed to 0x4                              |
  +--------+------+-------------------------------------------------------+
  |   2    |  s32 | Error count                                           |
  |        |      |  0: this rule will be ignored                         |
  |        |      |  positive: the rule will always take effect           |
  |        |      |  negative: the rule takes effect n times where -n is  |
  |        |      |            the value given. Ignored after n times     |
  +--------+------+-------------------------------------------------------+
  |   3    |  x8  | SCSI command opcode, 0xff for all commands            |
  +--------+------+-------------------------------------------------------+

Examples:

    error=/sys/kernel/debug/scsi_debug/0:0:0:1/error
    echo "4 -10 0x12" > ${error}

will make the device return FAILED when trying to reset LUN with inquiry
command 10 times.

    error=/sys/kernel/debug/scsi_debug/0:0:0:1/error
    echo "4 -10 0xff" > ${error}

will make the device return FAILED when trying to reset LUN 10 times.

Usually we do not care about what command it is when trying to perform
reset LUN, so 0xff could be applied.

Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Link: https://lore.kernel.org/r/20231010092051.608007-9-haowenchao2@huawei.com
Tested-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: scsi_debug: Add new error injection type: Abort Failed
Wenchao Hao [Tue, 10 Oct 2023 09:20:48 +0000 (17:20 +0800)]
scsi: scsi_debug: Add new error injection type: Abort Failed

Add error injection type 3 to make scsi_debug_abort() return FAILED.  Fail
abort command format:

  +--------+------+-------------------------------------------------------+
  | Column | Type | Description                                           |
  +--------+------+-------------------------------------------------------+
  |   1    |  u8  | Error type, fixed to 0x3                              |
  +--------+------+-------------------------------------------------------+
  |   2    |  s32 | Error count                                           |
  |        |      |  0: this rule will be ignored                         |
  |        |      |  positive: the rule will always take effect           |
  |        |      |  negative: the rule takes effect n times where -n is  |
  |        |      |            the value given. Ignored after n times     |
  +--------+------+-------------------------------------------------------+
  |   3    |  x8  | SCSI command opcode, 0xff for all commands            |
  +--------+------+-------------------------------------------------------+

Examples:

    error=/sys/kernel/debug/scsi_debug/0:0:0:1/error
    echo "3 -10 0x12" > ${error}

will make the device return FAILED when aborting inquiry command 10 times.

Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Link: https://lore.kernel.org/r/20231010092051.608007-8-haowenchao2@huawei.com
Tested-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: scsi_debug: Set command result and sense data if error is injected
Wenchao Hao [Tue, 10 Oct 2023 09:20:47 +0000 (17:20 +0800)]
scsi: scsi_debug: Set command result and sense data if error is injected

If a fail command error is injected, set the command's status and sense
data then finish this SCSI command.

Set SCSI command's status and sense data format:

  +--------+------+-------------------------------------------------------+
  | Column | Type | Description                                           |
  +--------+------+-------------------------------------------------------+
  |   1    |  u8  | Error type, fixed to 0x2                              |
  +--------+------+-------------------------------------------------------+
  |   2    |  s32 | Error Count                                           |
  |        |      |  0: the rule will be ignored                          |
  |        |      |  positive: the rule will always take effect           |
  |        |      |  negative: the rule takes effect n times where -n is  |
  |        |      |            the value given. Ignored after n times     |
  +--------+------+-------------------------------------------------------+
  |   3    |  x8  | SCSI command opcode, 0xff for all commands            |
  +--------+------+-------------------------------------------------------+
  |   4    |  x8  | Host byte in scsi_cmd::status                         |
  |        |      | [scsi_cmd::status has 32 bits holding these 3 bytes]  |
  +--------+------+-------------------------------------------------------+
  |   5    |  x8  | Driver byte in scsi_cmd::status                       |
  +--------+------+-------------------------------------------------------+
  |   6    |  x8  | SCSI Status byte in scsi_cmd::status                  |
  +--------+------+-------------------------------------------------------+
  |   7    |  x8  | SCSI Sense Key in scsi_cmnd                           |
  +--------+------+-------------------------------------------------------+
  |   8    |  x8  | SCSI ASC in scsi_cmnd                                 |
  +--------+------+-------------------------------------------------------+
  |   9    |  x8  | SCSI ASCQ in scsi_cmnd                                |
  +--------+------+-------------------------------------------------------+

Examples:
    error=/sys/kernel/debug/scsi_debug/0:0:0:1/error
    echo "2 -10 0x88 0 0 0x2 0x3 0x11 0x0" >${error}

will make device's read command return with media error with additional
sense of "Unrecovered read error" (UNC):

Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Link: https://lore.kernel.org/r/20231010092051.608007-7-haowenchao2@huawei.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: scsi_debug: Return failed value if error is injected
Wenchao Hao [Tue, 10 Oct 2023 09:20:46 +0000 (17:20 +0800)]
scsi: scsi_debug: Return failed value if error is injected

If a fail queuecommand error is injected, return the failed value defined
in the rule from queuecommand.

Make queuecommand return format:

  +--------+------+-------------------------------------------------------+
  | Column | Type | Description                                           |
  +--------+------+-------------------------------------------------------+
  |   1    |  u8  | Error type, fixed to 0x1                              |
  +--------+------+-------------------------------------------------------+
  |   2    |  s32 | Error count                                           |
  |        |      |  0: this rule will be ignored                         |
  |        |      |  positive: the rule will always take effect           |
  |        |      |  negative: the rule takes effect n times where -n is  |
  |        |      |            the value given. Ignored after n times     |
  +--------+------+-------------------------------------------------------+
  |   3    |  x8  | SCSI command opcode, 0xff for all commands            |
  +--------+------+-------------------------------------------------------+
  |   4    |  x32 | The queuecommand() return value we want               |
  +--------+------+-------------------------------------------------------+

Examples:

    error=/sys/kernel/debug/scsi_debug/0:0:0:1/error
    echo "1 1 0x12 0x1055" > ${error}

will make each INQUIRY command sent to that device return 0x1055
(SCSI_MLQUEUE_HOST_BUSY).

Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Link: https://lore.kernel.org/r/20231010092051.608007-6-haowenchao2@huawei.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: scsi_debug: Time out command if the error is injected
Wenchao Hao [Tue, 10 Oct 2023 09:20:45 +0000 (17:20 +0800)]
scsi: scsi_debug: Time out command if the error is injected

If a timeout error is injected, return 0 from scsi_debug_queuecommand to
make the command time out.

Time out SCSI command format:

  +--------+------+-------------------------------------------------------+
  | Column | Type | Description                                           |
  +--------+------+-------------------------------------------------------+
  |   1    |  u8  | Error type, fixed to 0x0                              |
  +--------+------+-------------------------------------------------------+
  |   2    |  s32 | Error count                                           |
  |        |      |  0: this rule will be ignored                         |
  |        |      |  positive: the rule will always take effect           |
  |        |      |  negative: the rule takes effect n times where -n is  |
  |        |      |            the value given. Ignored after n times     |
  +--------+------+-------------------------------------------------------+
  |   3    |  x8  | SCSI command opcode, 0xff for all commands            |
  +--------+------+-------------------------------------------------------+

Examples:

    error=/sys/kernel/debug/scsi_debug/0:0:0:1/error
    echo "0 -10 0x12" > ${error}

will make the device's inquiry command time out 10 times.

    echo "0 1 0x12" > ${error}

will make the device's inquiry time out each time it is invoked on this
device.

Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Link: https://lore.kernel.org/r/20231010092051.608007-5-haowenchao2@huawei.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: scsi_debug: Define grammar to remove added error injection
Wenchao Hao [Tue, 10 Oct 2023 09:20:44 +0000 (17:20 +0800)]
scsi: scsi_debug: Define grammar to remove added error injection

The grammar to remove error injection is a line with fixed 3 columns
separated by spaces.

First column is fixed to "-". It tells this is a removal operation.  Second
column is the error code to match.  Third column is the scsi command to
match.

For example the following command would remove timeout injection of inquiry
command:

    echo "- 0 0x12" > /sys/kernel/debug/scsi_debug/0:0:0:1/error

Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Link: https://lore.kernel.org/r/20231010092051.608007-4-haowenchao2@huawei.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: scsi_debug: Add interface to manage error injection for a single device
Wenchao Hao [Tue, 10 Oct 2023 09:20:43 +0000 (17:20 +0800)]
scsi: scsi_debug: Add interface to manage error injection for a single device

This new facility uses the debugfs pseudo file system which is typically
mounted under the /sys/kernel/debug directory and requires root permissions
to access.

The interface file is found at /sys/kernel/debug/scsi_debug/<h:c:t:l>/error
where <h:c:t:l> identifies the device (logical unit (LU)) to inject errors
on.

For the following description the ${error} environment variable is assumed
to be set to/sys/kernel/debug/scsi_debug/1:0:0:0/error where 1:0:0:0 is a
pseudo device (LU) owned by the scsi_debug driver. Rules are written to
${error} in the normal sysfs fashion (e.g. 'echo "0 -2 0x12" > ${error}').

More than one rule can be active on a device at a time and inactive rules
(i.e. those whose error count is 0) remain in the rule listing. The
existing rules can be read with 'cat ${error}' with oneline output for each
rule.

The interface format is line-by-line, each line is an error injection rule.
Each rule contains integers separated by spaces, the first three columns
correspond to "Error code", "Error count" and "SCSI command", other
columns depend on Error code.

General rule format:
  +--------+------+-------------------------------------------------------+
  | Column | Type | Description                                           |
  +--------+------+-------------------------------------------------------+
  |   1    |  u8  | Error code                                            |
  |        |      |  0: timeout SCSI command                              |
  |        |      |  1: fail queuecommand, make queuecommand return       |
  |        |      |     given value                                       |
  |        |      |  2: fail command, finish command with SCSI status,    |
  |        |      |     sense key and ASC/ASCQ values                     |
  |        |      |  3: make abort commands for specific command fail     |
  |        |      |  4: make reset lun for specific command fail          |
  +--------+------+-------------------------------------------------------+
  |   2    |  s32 | Error count                                           |
  |        |      |  0: this rule will be ignored                         |
  |        |      |  positive: the rule will always take effect           |
  |        |      |  negative: the rule takes effect n times where -n is  |
  |        |      |            the value given. Ignored after n times     |
  +--------+------+-------------------------------------------------------+
  |   3    |  x8  | SCSI command opcode, 0xff for all commands            |
  +--------+------+-------------------------------------------------------+
  |  ...   |  xxx | Error type specific fields                            |
  +--------+------+-------------------------------------------------------+

Notes:

 - When multiple error inject rules are added for the same SCSI command,
   the one with smaller error code will take effect (and the others will be
   ignored).

 - If the same error (i.e. same Error code and SCSI command) is added, the
   older one will be overwritten..

 - Currently, the basic types are (u8/u16/u32/u64/s8/s16/s32/s64) and the
   hexadecimal types (x8/x16/x32/x64).

 - Where a hexadecimal value is expected (e.g. Column 3: SCSI command
   opcode) the "0x" prefix is optional on the value (e.g. the INQUIRY
   opcode can be given as '0x12' or '12').

 - When the Error count is negative, reading ${error} will show that value
   incrementing, stopping when it gets to 0.

Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Link: https://lore.kernel.org/r/20231010092051.608007-3-haowenchao2@huawei.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: scsi_debug: Create scsi_debug directory in the debugfs filesystem
Wenchao Hao [Tue, 10 Oct 2023 09:20:42 +0000 (17:20 +0800)]
scsi: scsi_debug: Create scsi_debug directory in the debugfs filesystem

Create directory scsi_debug in the root of the debugfs filesystem.  Prepare
to add interface for manage error injection.

Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Link: https://lore.kernel.org/r/20231010092051.608007-2-haowenchao2@huawei.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoMerge patch series "lpfc: Update lpfc to revision 14.2.0.15"
Martin K. Petersen [Fri, 13 Oct 2023 21:00:47 +0000 (17:00 -0400)]
Merge patch series "lpfc: Update lpfc to revision 14.2.0.15"

Justin Tee <justintee8345@gmail.com> says:

Update lpfc to revision 14.2.0.15

This patch set contains error handling fixes, ELS bug fixes, and
logging improvements.

The patches were cut against Martin's 6.7/scsi-queue tree.

Link: https://lore.kernel.org/r/20231009161812.97232-1-justintee8345@gmail.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: lpfc: Update lpfc version to 14.2.0.15
Justin Tee [Mon, 9 Oct 2023 16:18:12 +0000 (09:18 -0700)]
scsi: lpfc: Update lpfc version to 14.2.0.15

Update lpfc version to 14.2.0.15.

Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Link: https://lore.kernel.org/r/20231009161812.97232-7-justintee8345@gmail.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: lpfc: Introduce LOG_NODE_VERBOSE messaging flag
Justin Tee [Mon, 9 Oct 2023 16:18:11 +0000 (09:18 -0700)]
scsi: lpfc: Introduce LOG_NODE_VERBOSE messaging flag

The preexisting LOG_NODE message flag frequently spams a subset of the same
log messages during normal FC driver operations.  When analyzing driver
logs, this sometimes leads to difficulty in troubleshooting.

Because LOG_IP log message flag is unused, convert it to a new
LOG_NODE_VERBOSE flag.  The LOG_NODE_VERBOSE shall specifically be used for
diagnosing issues that require precise ndlp tracking detail.

Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Link: https://lore.kernel.org/r/20231009161812.97232-6-justintee8345@gmail.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: lpfc: Validate ELS LS_ACC completion payload
Justin Tee [Mon, 9 Oct 2023 16:18:10 +0000 (09:18 -0700)]
scsi: lpfc: Validate ELS LS_ACC completion payload

A WCQE success completion status does not guarantee valid LS_ACC receipt
for ELS commands.  So, introduce a small helper routine that validates ELS
LS_ACC frames in ELS cmpl routines.

Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Link: https://lore.kernel.org/r/20231009161812.97232-5-justintee8345@gmail.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: lpfc: Reject received PRLIs with only initiator fcn role for NPIV ports
Justin Tee [Mon, 9 Oct 2023 16:18:09 +0000 (09:18 -0700)]
scsi: lpfc: Reject received PRLIs with only initiator fcn role for NPIV ports

Currently, NPIV ports send PRLI_ACC to all received unsolicited PRLI
requests.  For an NPIV port, there is no point to PRLI_ACC if the received
PRLI request has the initiator function bit set and the target function bit
unset.  Modify the lpfc_rcv_prli_support_check() routine to send a PRLI_RJT
in such cases.  NPIV ports are expected to send PRLI_ACC only if the Target
function bit is set.

Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Link: https://lore.kernel.org/r/20231009161812.97232-4-justintee8345@gmail.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: lpfc: Treat IOERR_SLI_DOWN I/O completion status the same as pci offline
Justin Tee [Mon, 9 Oct 2023 16:18:08 +0000 (09:18 -0700)]
scsi: lpfc: Treat IOERR_SLI_DOWN I/O completion status the same as pci offline

During receipt of a hardware error attention ACQE, IOERR_SLI_DOWN status is
set by the driver for all outstanding I/Os.

In such hardware error attention cases, we can treat the situation exactly
the same as pci_channel_offline.  Thus, add IOERR_SLI_DOWN status to the
same category as pci_channel_offline handling in lpfc_nvme_io_cmd_cmpl.

Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Link: https://lore.kernel.org/r/20231009161812.97232-3-justintee8345@gmail.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: lpfc: Remove unnecessary zero return code assignment in lpfc_sli4_hba_setup
Justin Tee [Mon, 9 Oct 2023 16:18:07 +0000 (09:18 -0700)]
scsi: lpfc: Remove unnecessary zero return code assignment in lpfc_sli4_hba_setup

In order to enter the !rc if statement block in question, rc had to have
been zero to begin with.  Thus, the rc = 0 assignment is unnecessary and
can be removed.

Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Link: https://lore.kernel.org/r/20231009161812.97232-2-justintee8345@gmail.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoMerge patch series "megaraid_sas: Driver version update to 07.727.03.00-rc1"
Martin K. Petersen [Fri, 13 Oct 2023 20:52:47 +0000 (16:52 -0400)]
Merge patch series "megaraid_sas: Driver version update to 07.727.03.00-rc1"

Chandrakanth patil <chandrakanth.patil@broadcom.com> says:

This set of patches includes critical fixes, and updates to the
maintainer list.

Link: https://lore.kernel.org/r/20231003110021.168862-1-chandrakanth.patil@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: megaraid_sas: Revision of Maintainer List
Chandrakanth patil [Tue, 3 Oct 2023 11:00:21 +0000 (16:30 +0530)]
scsi: megaraid_sas: Revision of Maintainer List

Given my active involvement in megaraid_sas development, I am including
myself in the maintainers list.

Signed-off-by: Chandrakanth patil <chandrakanth.patil@broadcom.com>
Link: https://lore.kernel.org/r/20231003110021.168862-5-chandrakanth.patil@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: megaraid_sas: Driver version update to 07.727.03.00-rc1
Chandrakanth patil [Tue, 3 Oct 2023 11:00:20 +0000 (16:30 +0530)]
scsi: megaraid_sas: Driver version update to 07.727.03.00-rc1

Driver version update.

Signed-off-by: Chandrakanth patil <chandrakanth.patil@broadcom.com>
Link: https://lore.kernel.org/r/20231003110021.168862-4-chandrakanth.patil@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: megaraid_sas: Log message when controller reset is requested but not issued
Chandrakanth patil [Tue, 3 Oct 2023 11:00:19 +0000 (16:30 +0530)]
scsi: megaraid_sas: Log message when controller reset is requested but not issued

The driver now includes the print message 'IO is completed, no reset is
required' when a reset is requested but not issued. This message is
displayed only when pending SCSI IO is completed before issuing the reset.

Signed-off-by: Chandrakanth patil <chandrakanth.patil@broadcom.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Link: https://lore.kernel.org/r/20231003110021.168862-3-chandrakanth.patil@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: megaraid_sas: Increase register read retry rount from 3 to 30 for selected...
Chandrakanth patil [Tue, 3 Oct 2023 11:00:18 +0000 (16:30 +0530)]
scsi: megaraid_sas: Increase register read retry rount from 3 to 30 for selected registers

In BMC environments with concurrent access to multiple registers, certain
registers occasionally yield a value of 0 even after 3 retries due to
hardware errata. As a fix, we have extended the retry count from 3 to 30.

The same errata applies to the mpt3sas driver, and a similar patch has
been accepted. Please find more details in the mpt3sas patch reference
link.

Link: https://lore.kernel.org/r/20230829090020.5417-2-ranjan.kumar@broadcom.com
Fixes: 272652fcbf1a ("scsi: megaraid_sas: add retry logic in megasas_readl")
Cc: stable@vger.kernel.org
Signed-off-by: Chandrakanth patil <chandrakanth.patil@broadcom.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Link: https://lore.kernel.org/r/20231003110021.168862-2-chandrakanth.patil@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoMerge patch series "scsi: sshdr and retry fixes"
Martin K. Petersen [Fri, 13 Oct 2023 20:38:26 +0000 (16:38 -0400)]
Merge patch series "scsi: sshdr and retry fixes"

Mike Christie <michael.christie@oracle.com> says:

The following patches were made over Linus tree (Martin's 6.7 branch
was missing some changes to sd.c). They only contain the sshdr and
rdac retry fixes from the "Allow scsi_execute users to control
retries" patchset.

The patches in this set are reviewed and tested but the changes to how
we do retries will take a little longer and require more testing, so I
broke up the series to make them easier to review.

Link: https://lore.kernel.org/r/20231004210013.5601-1-michael.christie@oracle.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: sr: Fix sshdr use in sr_get_events
Mike Christie [Wed, 4 Oct 2023 21:00:13 +0000 (16:00 -0500)]
scsi: sr: Fix sshdr use in sr_get_events

If scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we
shouldn't access the sshdr. If it returns 0, then the cmd executed
successfully, so there is no need to check the sshdr. This has us access
the sshdr when we get a return value > 0.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20231004210013.5601-13-michael.christie@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: sd: Fix sshdr use in cache_type_store
Mike Christie [Wed, 4 Oct 2023 21:00:12 +0000 (16:00 -0500)]
scsi: sd: Fix sshdr use in cache_type_store

If scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we
shouldn't access the sshdr. If it returns 0, then the cmd executed
successfully, so there is no need to check the sshdr. This has us access
the sshdr when we get a return value > 0.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20231004210013.5601-12-michael.christie@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: Fix sshdr use in scsi_cdl_enable
Mike Christie [Wed, 4 Oct 2023 21:00:11 +0000 (16:00 -0500)]
scsi: Fix sshdr use in scsi_cdl_enable

If scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we
shouldn't access the sshdr. If it returns 0, then the cmd executed
successfully, so there is no need to check the sshdr. This has us access
the sshdr when we get a return value > 0.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20231004210013.5601-11-michael.christie@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: Fix sshdr use in scsi_test_unit_ready
Mike Christie [Wed, 4 Oct 2023 21:00:10 +0000 (16:00 -0500)]
scsi: Fix sshdr use in scsi_test_unit_ready

If scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we
shouldn't access the sshdr. If it returns 0, then the cmd executed
successfully, so there is no need to check the sshdr. This has us access
the sshdr when we get a return value > 0.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20231004210013.5601-10-michael.christie@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: sd: Fix scsi_mode_sense caller's sshdr use
Mike Christie [Wed, 4 Oct 2023 21:00:09 +0000 (16:00 -0500)]
scsi: sd: Fix scsi_mode_sense caller's sshdr use

The sshdr passed into scsi_execute_cmd is only initialized if
scsi_execute_cmd returns >= 0, and scsi_mode_sense will convert all non
good statuses like check conditions to -EIO. This has scsi_mode_sense
callers that were possibly accessing an uninitialized sshdrs to only
access it if we got -EIO.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20231004210013.5601-9-michael.christie@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: spi: Fix sshdr use
Mike Christie [Wed, 4 Oct 2023 21:00:07 +0000 (16:00 -0500)]
scsi: spi: Fix sshdr use

If scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we
shouldn't access the sshdr. If it returns 0, then the cmd executed
successfully, so there is no need to check the sshdr. This has us access
the sshdr when we get a return value > 0.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20231004210013.5601-7-michael.christie@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: rdac: Fix sshdr use
Mike Christie [Wed, 4 Oct 2023 21:00:06 +0000 (16:00 -0500)]
scsi: rdac: Fix sshdr use

If scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we
shouldn't access the sshdr. If it returns 0, then the cmd executed
successfully, so there is no need to check the sshdr. This has us access
the sshdr when we get a return value > 0.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20231004210013.5601-6-michael.christie@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: rdac: Fix send_mode_select retry handling
Mike Christie [Wed, 4 Oct 2023 21:00:05 +0000 (16:00 -0500)]
scsi: rdac: Fix send_mode_select retry handling

If send_mode_select retries scsi_execute_cmd it will leave err set to
SCSI_DH_RETRY/SCSI_DH_IMM_RETRY. If on the retry, the command is
successful, then SCSI_DH_RETRY/SCSI_DH_IMM_RETRY will be returned to the
scsi_dh activation caller. On the retry, we will then detect the previous
MODE SELECT had worked, and so we will return success.

This patch has us return the correct return value, so we can avoid the
extra scsi_dh activation call and to avoid failures if the caller had hit
its activation retry limit and does not end up retrying.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20231004210013.5601-5-michael.christie@oracle.com
Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: hp_sw: Fix sshdr use
Mike Christie [Wed, 4 Oct 2023 21:00:04 +0000 (16:00 -0500)]
scsi: hp_sw: Fix sshdr use

If scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we
shouldn't access the sshdr. If it returns 0, then the cmd executed
successfully, so there is no need to check the sshdr. This has us access
the sshdr when we get a return value > 0.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20231004210013.5601-4-michael.christie@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: sd: Fix sshdr use in sd_spinup_disk
Mike Christie [Wed, 4 Oct 2023 21:00:03 +0000 (16:00 -0500)]
scsi: sd: Fix sshdr use in sd_spinup_disk

If scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we
shouldn't access the sshdr. If it returns 0, then the cmd executed
successfully, so there is no need to check the sshdr. This has us access
the sshdr when we get a return value > 0.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20231004210013.5601-3-michael.christie@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: sd: Fix sshdr use in read_capacity_16
Mike Christie [Wed, 4 Oct 2023 21:00:02 +0000 (16:00 -0500)]
scsi: sd: Fix sshdr use in read_capacity_16

If scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we
shouldn't access the sshdr. If it returns 0, then the cmd executed
successfully, so there is no need to check the sshdr. This has us access
the sshdr when we get a return value > 0.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20231004210013.5601-2-michael.christie@oracle.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoMerge patch series "scsi: target: Allow userspace to config cmd submission"
Martin K. Petersen [Fri, 13 Oct 2023 19:56:37 +0000 (15:56 -0400)]
Merge patch series "scsi: target: Allow userspace to config cmd submission"

Mike Christie <michael.christie@oracle.com> says:

The following patches were made over Linus's tree but apply over
Martin's branches. They allow userspace to configure how fabric
drivers submit cmds to backend drivers.

Right now loop and vhost use a worker thread, and the other drivers
submit from the contexts they receive/process the cmd from. For
multiple LUN cases where the target can queue more cmds than the
backend can handle then deferring to a worker thread is safest because
the backend driver can block when doing things like waiting for a free
request/tag. Deferring also helps when the target has to handle
transport level requests from the recv context.

For cases where the backend devices can queue everything the target
sends, then there is no need to defer to a workqueue and you can see a
perf boost of up to 26% for small IO workloads. For a nvme device and
vhost-scsi I can see with 4K IOs:

fio jobs        1       2       4       8       10
--------------------------------------------------
workqueue
submit        94K     190K    394K    770K    890K

direct
submit       128K     252K    488K    950K    -

Link: https://lore.kernel.org/r/1b1f7a5c-0988-45f9-b103-dfed2c0405b1@oracle.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: target: Export fabric driver direct submit settings
Mike Christie [Thu, 28 Sep 2023 02:09:07 +0000 (21:09 -0500)]
scsi: target: Export fabric driver direct submit settings

This exports the fabric driver's direct submit settings, so users know what
the driver supports. It will be helpful when they are exporting a device
through different targets and one doesn't support direct submission.

The new files allow the fabric to report what submission types they default
to and if they support direct submission:

default_submit_type:

 1 - TARGET_DIRECT_SUBMIT - If the user has not requested a specific value
     then the fabric requests direct submission.

 2 - TARGET_QUEUE_SUBMIT - If the user has not requested a specific value
     then the fabric requests queued submission.

Note that these fabric values are based on what the fabric driver currently
defaults to for compat with exiting setups.

direct_submit_supported:

 0 - The fabric does not support direct submission.

 1 - The fabric supports direct submission.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20230928020907.5730-8-michael.christie@oracle.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: target: core: Unexport target_queue_submission()
Mike Christie [Thu, 28 Sep 2023 02:09:06 +0000 (21:09 -0500)]
scsi: target: core: Unexport target_queue_submission()

target_queue_submission() is not called by drivers anymore so unexport it.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20230928020907.5730-7-michael.christie@oracle.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: target: Allow userspace to request direct submissions
Mike Christie [Thu, 28 Sep 2023 02:09:05 +0000 (21:09 -0500)]
scsi: target: Allow userspace to request direct submissions

This allows userspace to request the fabric drivers do direct submissions
if they support it. With the new device file, submit_type, users can
write 0 - 2 to control how commands are submitted to the backend:

 0 - TARGET_FABRIC_DEFAULT_SUBMIT - LIO will use the fabric's default
     submission type. This is the default for compat.

 1 - TARGET_DIRECT_SUBMIT - LIO will submit the cmd to the backend from the
     calling context if the fabric the cmd was received on supports it,
     else it will use the fabric's default type.

 2 - TARGET_QUEUE_SUBMIT - LIO will queue the cmd to the LIO submission
     workqueue which will pass it to the backend.

When using an NVMe drive and vhost-scsi with direct submission we see
around a 20% improvement in 4K I/Os:

fio jobs        1       2       4       8       10
--------------------------------------------------
defer           94K     190K    394K    770K    890K
direct          128K    252K    488K    950K    -

And when using the queueing mode, we now no longer see issues like where
the iSCSI tx thread is blocked in the block layer waiting on a tag so it
can't respond to a nop or perform I/Os for other LUs.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20230928020907.5730-6-michael.christie@oracle.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: target: core: Kill transport_handle_cdb_direct()
Mike Christie [Thu, 28 Sep 2023 02:09:04 +0000 (21:09 -0500)]
scsi: target: core: Kill transport_handle_cdb_direct()

Move the code from transport_handle_cdb_direct() to target_submit() and
have iSCSI call target_submit().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20230928020907.5730-5-michael.christie@oracle.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: target: core: Move buffer clearing hack
Mike Christie [Thu, 28 Sep 2023 02:09:03 +0000 (21:09 -0500)]
scsi: target: core: Move buffer clearing hack

Move the hack to clear some buffers to transport_handle_cdb_direct() so we
can eventually merge transport_handle_cdb_direct() and target_submit().

This also fixes up the comment so it's clear it was only for udev and
reflects that the referenced function does not exist and we now allow more
than 1 page for control CDBs.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20230928020907.5730-4-michael.christie@oracle.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: target: core: Move core_alua_check_nonop_delay() call
Mike Christie [Thu, 28 Sep 2023 02:09:02 +0000 (21:09 -0500)]
scsi: target: core: Move core_alua_check_nonop_delay() call

Move core_alua_check_nonop_delay() to transport_handle_cdb_direct() so the
iSCSI target driver doesn't have to call as many core functions
directly. We will eventually merge transport_handle_cdb_direct and
target_submit so iSCSI and the other drivers call a common function.

It will also be helpful as preparation for future changes which allow the
iSCSI target to defer command submission to the LIO submission workqueue,
because we will have a common submission function for that which will be
based on transport_handle_cdb_direct()/target_submit().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20230928020907.5730-3-michael.christie@oracle.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: target: Have drivers report if they support direct submissions
Mike Christie [Thu, 28 Sep 2023 02:09:01 +0000 (21:09 -0500)]
scsi: target: Have drivers report if they support direct submissions

In some cases, like with multiple LUN targets or where the target has to
respond to transport level requests from the receiving context it can be
better to defer cmd submission to a helper thread. If the backend driver
blocks on something like request/tag allocation it can block the entire
target submission path and other LUs and transport IO on that session.

In other cases like single LUN targets with storage that can support all
the commands that the target can queue, then it's best to submit the cmd
to the backend from the target's cmd receiving context.

Subsequent commits will allow the user to config what they prefer, but
drivers like loop can't directly submit because they can be called from a
context that can't sleep. And, drivers like vhost-scsi can support direct
submission, but need to keep their default behavior of deferring execution
to avoid possible regressions where the backend can block.

Make the drivers tell LIO core if they support direct submissions and their
current default, so we can prevent users from misconfiguring the system and
initialize devices correctly.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20230928020907.5730-2-michael.christie@oracle.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: target: iscs: Make write_pending_must_be_called a bit field
Mike Christie [Thu, 28 Sep 2023 02:09:00 +0000 (21:09 -0500)]
scsi: target: iscs: Make write_pending_must_be_called a bit field

Subsequent commits add more on/off type of settings to the
target_core_fabric_ops struct so this makes write_pending_must_be_called a
bit field instead of a bool to better organize the settings.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20230928020907.5730-1-michael.christie@oracle.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoMerge patch series "scsi: EH rework prep patches, part 1"
Martin K. Petersen [Fri, 13 Oct 2023 18:25:20 +0000 (14:25 -0400)]
Merge patch series "scsi: EH rework prep patches, part 1"

Hannes Reinecke <hare@suse.de> says:

Hi all,

(taking up an old thread:) here's the first batch of patches for my EH
rework.  It modifies the reset callbacks for SCSI drivers such that
the final conversion to drop the 'struct scsi_cmnd' argument and use
the entity in question (host, bus, target, device) as the argument to
the SCSI EH callbacks becomes possible.  The first part covers drivers
which just requires minor tweaks.

Link: https://lore.kernel.org/r/20231002154328.43718-1-hare@suse.de
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: mpi3mr: Split off bus_reset function from host_reset
Hannes Reinecke [Mon, 2 Oct 2023 15:43:28 +0000 (17:43 +0200)]
scsi: mpi3mr: Split off bus_reset function from host_reset

SCSI EH host reset is the final callback in the escalation chain; once we
reach this we need to reset the controller.  As such it defeats the purpose
to skip controller reset if no I/Os are pending and the RAID device is to
be reset; especially after kexec there might be stale commands pending in
firmware for which we have no reference whatsoever.  So this patch splits
off the check for pending I/O into a 'bus_reset' function, and leaves the
actual controller reset to the host reset.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-19-hare@suse.de
Cc: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: Sathya Prakash Veerichetty <sathya.prakash@broadcom.com>
Cc: Sumit Saxena <sumit.saxena@broadcom.com>
Cc: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: pmcraid: Select device in pmcraid_eh_target_reset_handler()
Hannes Reinecke [Mon, 2 Oct 2023 15:43:27 +0000 (17:43 +0200)]
scsi: pmcraid: Select device in pmcraid_eh_target_reset_handler()

The reset code requires a device to be selected, but we shouldn't rely on
the command to provide a device for us. So select the first device on the
target when sending down a target reset.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-18-hare@suse.de
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: pmcraid: Select device in pmcraid_eh_bus_reset_handler()
Hannes Reinecke [Mon, 2 Oct 2023 15:43:26 +0000 (17:43 +0200)]
scsi: pmcraid: Select device in pmcraid_eh_bus_reset_handler()

The reset code requires a device to be selected, but we shouldn't rely on
the command to provide a device for us. So select the first device on the
bus when sending down a bus reset.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-17-hare@suse.de
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: qla1280: Separate out host reset function from qla1280_error_action()
Hannes Reinecke [Mon, 2 Oct 2023 15:43:25 +0000 (17:43 +0200)]
scsi: qla1280: Separate out host reset function from qla1280_error_action()

There's not much in common between host reset and all other error handlers,
so use a separate function here.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-16-hare@suse.de
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: sym53c8xx_2: Rework reset handling
Hannes Reinecke [Mon, 2 Oct 2023 15:43:24 +0000 (17:43 +0200)]
scsi: sym53c8xx_2: Rework reset handling

Split off the combined abort and device reset handling into distinct
functions. And rename the current device reset handler into a target reset
handler, seeing that it really is a target reset.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-15-hare@suse.de
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: sym53c8xx_2: Split off bus reset from host reset
Hannes Reinecke [Mon, 2 Oct 2023 15:43:23 +0000 (17:43 +0200)]
scsi: sym53c8xx_2: Split off bus reset from host reset

The current handler does both, bus reset and host reset.  So split them off
into two distinct functions.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-14-hare@suse.de
Cc: Matthew Wilcox <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: ips: Do not try to abort command from host reset
Hannes Reinecke [Mon, 2 Oct 2023 15:43:22 +0000 (17:43 +0200)]
scsi: ips: Do not try to abort command from host reset

The code for aborting an outstanding command is a copy of the functionality
from command abort. As we already have called this function once we reach
host reset there's no point in trying to do so again.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-13-hare@suse.de
Cc: Adaptec OEM Raid Solutions <aacraid@microsemi.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: megaraid: Pass in NULL scb for host reset
Hannes Reinecke [Mon, 2 Oct 2023 15:43:21 +0000 (17:43 +0200)]
scsi: megaraid: Pass in NULL scb for host reset

When calling a host reset we shouldn't rely on the command triggering the
reset, so allow megaraid_abort_and_reset() to be called with a NULL scb.
And drop the pointless 'bus_reset' and 'target_reset' handlers, which just
call the same function as host_reset.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-12-hare@suse.de
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: ibmvfc: Open-code reset loop for target reset
Hannes Reinecke [Mon, 2 Oct 2023 15:43:20 +0000 (17:43 +0200)]
scsi: ibmvfc: Open-code reset loop for target reset

For target reset we need a device to send the target reset to, so open-code
the loop in target reset to send the target reset TMF to the correct
device.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-11-hare@suse.de
Cc: Tyrel Datwyler <tyreld@linux.ibm.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: aic79xx: Do not reference SCSI command when resetting device
Hannes Reinecke [Mon, 2 Oct 2023 15:43:19 +0000 (17:43 +0200)]
scsi: aic79xx: Do not reference SCSI command when resetting device

When sending a device reset we should not take a reference to the SCSI
command.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-10-hare@suse.de
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: aic79xx: Make BUILD_SCSIID() a function
Hannes Reinecke [Mon, 2 Oct 2023 15:43:18 +0000 (17:43 +0200)]
scsi: aic79xx: Make BUILD_SCSIID() a function

Convert BUILD_SCSIID() into a function and add a scsi_device argument.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-9-hare@suse.de
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: aic7xxx: Do not reference SCSI command when resetting device
Hannes Reinecke [Mon, 2 Oct 2023 15:43:17 +0000 (17:43 +0200)]
scsi: aic7xxx: Do not reference SCSI command when resetting device

When sending a device reset we should not take a reference to the SCSI
command.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-8-hare@suse.de
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: aic7xxx: Make BUILD_SCSIID() a function
Hannes Reinecke [Mon, 2 Oct 2023 15:43:16 +0000 (17:43 +0200)]
scsi: aic7xxx: Make BUILD_SCSIID() a function

Convert BUILD_SCSIID() into a function and add a scsi_device argument.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-7-hare@suse.de
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: bnx2fc: Do not rely on a SCSI command for LUN or target reset
Hannes Reinecke [Mon, 2 Oct 2023 15:43:15 +0000 (17:43 +0200)]
scsi: bnx2fc: Do not rely on a SCSI command for LUN or target reset

When a LUN or target reset is issued, we should not rely on a SCSI command
to be present; we'll have to reset the entire device or target anyway.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-6-hare@suse.de
Cc: Saurav Kashyap <skashyap@marvell.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: qedf: Use FC rport as argument for qedf_initiate_tmf()
Hannes Reinecke [Mon, 2 Oct 2023 15:43:14 +0000 (17:43 +0200)]
scsi: qedf: Use FC rport as argument for qedf_initiate_tmf()

When sending a TMF we're only concerned with the rport and the LUN ID, so
use struct fc_rport as argument for qedf_initiate_tmf().

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-5-hare@suse.de
Cc: Saurav Kashyap <skashyap@marvell.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: message: fusion: Open-code mptfc_block_error_handler() for bus reset
Hannes Reinecke [Mon, 2 Oct 2023 15:43:13 +0000 (17:43 +0200)]
scsi: message: fusion: Open-code mptfc_block_error_handler() for bus reset

When calling bus_reset we have potentially several ports to be reset, so
this patch open-codes the existing mptfc_block_error_handler() to wait for
all ports attached to this bus.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-4-hare@suse.de
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: message: fusion: Correct definitions for mptscsih_dev_reset()
Hannes Reinecke [Mon, 2 Oct 2023 15:43:12 +0000 (17:43 +0200)]
scsi: message: fusion: Correct definitions for mptscsih_dev_reset()

mptscsih_dev_reset() is _not_ a device reset, but rather a target
reset. Nevertheless it's being used for either purpose.  This patch adds a
correct implementation for mptscsih_dev_reset(), and renames the original
function to mptscsih_target_reset().

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-3-hare@suse.de
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: message: fusion: Simplify mptfc_block_error_handler()
Hannes Reinecke [Mon, 2 Oct 2023 15:43:11 +0000 (17:43 +0200)]
scsi: message: fusion: Simplify mptfc_block_error_handler()

Instead of passing in a function to mptfc_block_error_handler() we can as
well return a status and call the function afterwards.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20231002154328.43718-2-hare@suse.de
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: ibmvfc: Use 'unsigned int' for single-bit bitfields in 'struct ibmvfc_host'
Nathan Chancellor [Tue, 10 Oct 2023 20:32:37 +0000 (13:32 -0700)]
scsi: ibmvfc: Use 'unsigned int' for single-bit bitfields in 'struct ibmvfc_host'

Clang warns (or errors with CONFIG_WERROR=y) several times along the
lines of:

  drivers/scsi/ibmvscsi/ibmvfc.c:650:17: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
    650 |                 vhost->reinit = 1;
        |                               ^ ~

A single-bit signed integer bitfield only has possible values of -1 and
0, not 0 and 1 like an unsigned one would. No context appears to check
the actual value of these bitfields, just whether or not it is zero.
However, it is easy enough to change the type of the fields to 'unsigned
int', which keeps the same size in memory and resolves the warning.

Fixes: 5144905884e2 ("scsi: ibmvfc: Use a bitfield for boolean flags")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/r/20231010-ibmvfc-fix-bitfields-type-v1-1-37e95b5a60e5@kernel.org
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup()
Wenchao Hao [Wed, 11 Oct 2023 13:03:50 +0000 (21:03 +0800)]
scsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup()

fc_lport_ptp_setup() did not check the return value of fc_rport_create()
which can return NULL and would cause a NULL pointer dereference. Address
this issue by checking return value of fc_rport_create() and log error
message on fc_rport_create() failed.

Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
Link: https://lore.kernel.org/r/20231011130350.819571-1-haowenchao2@huawei.com
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: cxgbi: Fix 'generated' typo
Muhammad Muzammil [Fri, 13 Oct 2023 05:51:21 +0000 (10:51 +0500)]
scsi: cxgbi: Fix 'generated' typo

Fix 'generated' typo.

Signed-off-by: Muhammad Muzammil <m.muzzammilashraf@gmail.com>
Link: https://lore.kernel.org/r/20231013055121.12310-1-m.muzzammilashraf@gmail.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: ufs: core: Fix abnormal scale up after scale down
Peter Wang [Thu, 31 Aug 2023 13:08:26 +0000 (21:08 +0800)]
scsi: ufs: core: Fix abnormal scale up after scale down

When no active_reqs, devfreq_monitor (thread A) will suspend clock scaling.
But it may have racing with clk_scaling.suspend_work (thread B) and
actually not suspend clock scaling (requeue after suspend).  Next time
after polling_ms, devfreq_monitor read clk_scaling.window_start_t = 0 then
scale up clock abnormal.

Below is racing step:
devfreq->work (Thread A)
devfreq_monitor
update_devfreq
.....
ufshcd_devfreq_target
queue_work(hba->clk_scaling.workq,
1    &hba->clk_scaling.suspend_work)
.....
5 queue_delayed_work(devfreq_wq, &devfreq->work,
msecs_to_jiffies(devfreq->profile->polling_ms));

2 hba->clk_scaling.suspend_work (Thread B)
ufshcd_clk_scaling_suspend_work
__ufshcd_suspend_clkscaling
devfreq_suspend_device(hba->devfreq);
3 cancel_delayed_work_sync(&devfreq->work);
4 hba->clk_scaling.window_start_t = 0;
.....

Signed-off-by: Peter Wang <peter.wang@mediatek.com>
Link: https://lore.kernel.org/r/20230831130826.5592-4-peter.wang@mediatek.com
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: ufs: core: Fix abnormal scale up after last cmd finish
Peter Wang [Thu, 31 Aug 2023 13:08:25 +0000 (21:08 +0800)]
scsi: ufs: core: Fix abnormal scale up after last cmd finish

When ufshcd_clk_scaling_suspend_work (thread A) running and new command
coming, ufshcd_clk_scaling_start_busy (thread B) may get host_lock after
thread A first time release host_lock. Then thread A second time get
host_lock will set clk_scaling.window_start_t = 0 which scale up clock
abnormal next polling_ms time.  Also inlines another
__ufshcd_suspend_clkscaling calls.

Below is racing step:
1 hba->clk_scaling.suspend_work (Thread A)
ufshcd_clk_scaling_suspend_work
2 spin_lock_irqsave(hba->host->host_lock, irq_flags);
3 hba->clk_scaling.is_suspended = true;
4 spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
__ufshcd_suspend_clkscaling
7 spin_lock_irqsave(hba->host->host_lock, flags);
8 hba->clk_scaling.window_start_t = 0;
9 spin_unlock_irqrestore(hba->host->host_lock, flags);

ufshcd_send_command (Thread B)
ufshcd_clk_scaling_start_busy
5 spin_lock_irqsave(hba->host->host_lock, flags);
....
6 spin_unlock_irqrestore(hba->host->host_lock, flags);

Signed-off-by: Peter Wang <peter.wang@mediatek.com>
Link: https://lore.kernel.org/r/20230831130826.5592-3-peter.wang@mediatek.com
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: ufs: core: Only suspend clock scaling if scaling down
Peter Wang [Thu, 31 Aug 2023 13:08:24 +0000 (21:08 +0800)]
scsi: ufs: core: Only suspend clock scaling if scaling down

If clock scale up and suspend clock scaling, ufs will keep high
performance/power mode but no read/write requests on going.  It is logic
wrong and have power concern.

Signed-off-by: Peter Wang <peter.wang@mediatek.com>
Link: https://lore.kernel.org/r/20230831130826.5592-2-peter.wang@mediatek.com
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: ufs: qcom: Remove unnecessary check
Dan Carpenter [Mon, 2 Oct 2023 07:03:35 +0000 (10:03 +0300)]
scsi: ufs: qcom: Remove unnecessary check

The "attr" pointer points to an offset into the "host" struct so it can't
be NULL.  Delete the if statement and pull the code in a tab.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/fe3b8fcd-64a7-4887-bddd-32239a88a6a3@moroto.mountain
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: ufs: ufs-pci: Switch to use acpi_evaluate_dsm_typed()
Andy Shevchenko [Mon, 2 Oct 2023 13:51:25 +0000 (16:51 +0300)]
scsi: ufs: ufs-pci: Switch to use acpi_evaluate_dsm_typed()

The acpi_evaluate_dsm_typed() provides a way to check the type of the
object evaluated by _DSM call. Use it instead of open coded variant.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20231002135125.2602895-1-andriy.shevchenko@linux.intel.com
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: ufs: core: Remove dev cmd clock scaling busy
Peter Wang [Wed, 4 Oct 2023 06:24:54 +0000 (14:24 +0800)]
scsi: ufs: core: Remove dev cmd clock scaling busy

If a dev command times out, clk_scaling.active_reqs is not decreased which
causes abnormal clock scaling.

It is complicated to handle different dev command timeout cases in both
legacy mode and MCQ mode. Besides, dev cmds are rarely used and the busy
time is short.

Remove clock scaling busy window for dev cmds like we do for UIC or TM cmds
which don't update busy window either.

Signed-off-by: Peter Wang <peter.wang@mediatek.com>
Link: https://lore.kernel.org/r/20231004062454.29165-1-peter.wang@mediatek.com
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: message: fusion: Replace deprecated strncpy() with strscpy()
Justin Stitt [Tue, 3 Oct 2023 22:15:45 +0000 (22:15 +0000)]
scsi: message: fusion: Replace deprecated strncpy() with strscpy()

strncpy() is deprecated for use on NUL-terminated destination strings [1]
and as such we should prefer more robust and less ambiguous string
interfaces.

The only caller of mptsas_exp_repmanufacture_info() is
mptsas_probe_one_phy() which can allocate rphy in either
sas_end_device_alloc() or sas_expander_alloc(). Both of which
zero-allocate:

|       rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);

... this is supplied to mptsas_exp_repmanufacture_info() as edev meaning
that no future NUL-padding of edev members is needed.

Considering the above, a suitable replacement is strscpy() [2] due to the
fact that it guarantees NUL-termination on the destination buffer without
unnecessarily NUL-padding.

Also use the more idiomatic strscpy() pattern of (dest, src, sizeof(dest)).

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20231003-strncpy-drivers-message-fusion-mptsas-c-v2-1-5ce07e60bd21@google.com
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: message: fusion: Replace deprecated strncpy() with strscpy_pad()
Justin Stitt [Wed, 27 Sep 2023 04:06:09 +0000 (04:06 +0000)]
scsi: message: fusion: Replace deprecated strncpy() with strscpy_pad()

strncpy() is deprecated for use on NUL-terminated destination strings [1]
and as such we should prefer more robust and less ambiguous string
interfaces.

Since all these structs are copied out to userspace let's keep them
NUL-padded by using strscpy_pad() which guarantees NUL-termination of the
destination buffer while also providing the NUL-padding behavior that
strncpy() has.

Let's also opt to use the more idiomatic strscpy() usage of: 'dest, src,
sizeof(dest)' in cases where the compiler can determine the size of the
destination buffer. Do this for all cases of strscpy...() in this file.

To be abundantly sure we don't leak stack data out to user space let's also
change a strscpy() to strscpy_pad(). This strscpy() was introduced in
commit dbe37c71d124 ("scsi: message: fusion: Replace all non-returning
strlcpy() with strscpy()")

Note that since we are creating these structs with a copy_from_user() and
modifying fields and then copying back out to the user it is probably OK
not to explicitly NUL-pad everything as any data leak is probably just data
from the user themselves. If this is too eager, let's opt for strscpy()
which is still in the spirit of removing deprecated strncpy() usage
treewide.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20230927-strncpy-drivers-message-fusion-mptctl-c-v1-1-bb2eddc1743c@google.com
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoscsi: ufs: core: WLUN send SSU timeout recovery
Peter Wang [Wed, 27 Sep 2023 03:35:57 +0000 (11:35 +0800)]
scsi: ufs: core: WLUN send SSU timeout recovery

When runtime PM send SSU times out, the SCSI core invokes
eh_host_reset_handler, in this case ufshcd_eh_host_reset_handler(), which
is then stuck waiting for flush_work(&hba->eh_work). However,
ufshcd_err_handler hangs in wait RPM resume. Do link recovery only in this
case. The following IO hang stack dump was observed:

kworker/4:0     D
<ffffffd7d31f6fb4> __switch_to+0x180/0x344
<ffffffd7d31f779c> __schedule+0x5ec/0xa14
<ffffffd7d31f7c3c> schedule+0x78/0xe0
<ffffffd7d31fefbc> schedule_timeout+0xb0/0x15c
<ffffffd7d31f8120> io_schedule_timeout+0x48/0x70
<ffffffd7d31f8e40> do_wait_for_common+0x108/0x19c
<ffffffd7d31f837c> wait_for_completion_io_timeout+0x50/0x78
<ffffffd7d2876bc0> blk_execute_rq+0x1b8/0x218
<ffffffd7d2b4297c> scsi_execute_cmd+0x148/0x238
<ffffffd7d2da7358> ufshcd_set_dev_pwr_mode+0xe8/0x244
<ffffffd7d2da7e40> __ufshcd_wl_resume+0x1e0/0x45c
<ffffffd7d2da7b28> ufshcd_wl_runtime_resume+0x3c/0x174
<ffffffd7d2b4f290> scsi_runtime_resume+0x7c/0xc8
<ffffffd7d2ae1d48> __rpm_callback+0xa0/0x410
<ffffffd7d2ae0128> rpm_resume+0x43c/0x67c
<ffffffd7d2ae1e98> __rpm_callback+0x1f0/0x410
<ffffffd7d2ae014c> rpm_resume+0x460/0x67c
<ffffffd7d2ae1450> pm_runtime_work+0xa4/0xac
<ffffffd7d22e39ac> process_one_work+0x208/0x598
<ffffffd7d22e3fc0> worker_thread+0x228/0x438
<ffffffd7d22eb038> kthread+0x104/0x1d4
<ffffffd7d22171a0> ret_from_fork+0x10/0x20

scsi_eh_0       D
<ffffffd7d31f6fb4> __switch_to+0x180/0x344
<ffffffd7d31f779c> __schedule+0x5ec/0xa14
<ffffffd7d31f7c3c> schedule+0x78/0xe0
<ffffffd7d31fef50> schedule_timeout+0x44/0x15c
<ffffffd7d31f8e40> do_wait_for_common+0x108/0x19c
<ffffffd7d31f8234> wait_for_completion+0x48/0x64
<ffffffd7d22deb88> __flush_work+0x260/0x2d0
<ffffffd7d22de918> flush_work+0x10/0x20
<ffffffd7d2da4728> ufshcd_eh_host_reset_handler+0x88/0xcc
<ffffffd7d2b41da4> scsi_try_host_reset+0x48/0xe0
<ffffffd7d2b410fc> scsi_eh_ready_devs+0x934/0xa40
<ffffffd7d2b41618> scsi_error_handler+0x168/0x374
<ffffffd7d22eb038> kthread+0x104/0x1d4
<ffffffd7d22171a0> ret_from_fork+0x10/0x20

kworker/u16:5   D
<ffffffd7d31f6fb4> __switch_to+0x180/0x344
<ffffffd7d31f779c> __schedule+0x5ec/0xa14
<ffffffd7d31f7c3c> schedule+0x78/0xe0
<ffffffd7d2adfe00> rpm_resume+0x114/0x67c
<ffffffd7d2adfca8> __pm_runtime_resume+0x70/0xb4
<ffffffd7d2d9cf48> ufshcd_err_handler+0x1a0/0xe68
<ffffffd7d22e39ac> process_one_work+0x208/0x598
<ffffffd7d22e3fc0> worker_thread+0x228/0x438
<ffffffd7d22eb038> kthread+0x104/0x1d4
<ffffffd7d22171a0> ret_from_fork+0x10/0x20

Signed-off-by: Peter Wang <peter.wang@mediatek.com>
Link: https://lore.kernel.org/r/20230927033557.13801-1-peter.wang@mediatek.com
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
8 months agoMerge patch series "ibmvfc: fixes and generic prep work for NVMeoF support"
Martin K. Petersen [Tue, 10 Oct 2023 01:08:34 +0000 (21:08 -0400)]
Merge patch series "ibmvfc: fixes and generic prep work for NVMeoF support"

Tyrel Datwyler <tyreld@linux.ibm.com> says:

This series includes a couple minor fixes, generalization of some code
that is not protocol specific, and a reworking of the way event pool
buffers are accounted for by the driver. This is a precursor to a
series to follow that introduces support for NVMeoF protocol with
ibmvfc.

Link: https://lore.kernel.org/r/20230921225435.3537728-1-tyreld@linux.ibm.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
9 months agoscsi: fnic: Clean up some inconsistent indenting
Jiapeng Chong [Fri, 22 Sep 2023 10:06:57 +0000 (18:06 +0800)]
scsi: fnic: Clean up some inconsistent indenting

No functional modification involved.

drivers/scsi/fnic/fnic_fcs.c:152 fnic_handle_link() warn: inconsistent indenting.

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=6678
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230922100657.14566-1-jiapeng.chong@linux.alibaba.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
9 months agoscsi: target: tcmu: Annotate struct tcmu_tmr with __counted_by
Kees Cook [Fri, 22 Sep 2023 17:53:01 +0000 (10:53 -0700)]
scsi: target: tcmu: Annotate struct tcmu_tmr with __counted_by

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct tcmu_tmr.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Bodo Stroesser <bostroesser@gmail.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
Cc: target-devel@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230922175300.work.148-kees@kernel.org
Reviewed-by: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Reviewed-by: Bodo Stroesser <bostroesser@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
9 months agoMerge patch series "UFS core patches"
Martin K. Petersen [Wed, 27 Sep 2023 15:14:07 +0000 (11:14 -0400)]
Merge patch series "UFS core patches"

Bart Van Assche <bvanassche@acm.org> says:

Hi Martin,

Please consider these UFS core patches for the next merge window.

Thanks,

Bart.

Link: https://lore.kernel.org/r/20230921192335.676924-1-bvanassche@acm.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
9 months agoscsi: ufs: core: Set the Command Priority (CP) flag for RT requests
Bart Van Assche [Thu, 21 Sep 2023 19:22:49 +0000 (12:22 -0700)]
scsi: ufs: core: Set the Command Priority (CP) flag for RT requests

Make the UFS device execute realtime (RT) requests before other requests.
This will be used in Android to reduce the I/O latency of the foreground
app.

Note: UFS devices do not support CDL so using CDL is not a viable
alternative.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20230921192335.676924-5-bvanassche@acm.org
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
9 months agoscsi: ufs: core: Simplify ufshcd_comp_scsi_upiu()
Bart Van Assche [Thu, 21 Sep 2023 19:22:48 +0000 (12:22 -0700)]
scsi: ufs: core: Simplify ufshcd_comp_scsi_upiu()

ufshcd_comp_scsi_upiu() has one caller and that caller ensures that
lrbp->cmd != NULL. Hence leave out the lrbp->cmd check from
ufshcd_comp_scsi_upiu().

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20230921192335.676924-4-bvanassche@acm.org
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
9 months agoscsi: ufs: core: Move the 4K alignment code into the Exynos driver
Bart Van Assche [Thu, 21 Sep 2023 19:22:47 +0000 (12:22 -0700)]
scsi: ufs: core: Move the 4K alignment code into the Exynos driver

The DMA alignment for the Exynos controller follows directly from the PRDT
segment size configured in ufs-exynos.c. Hence, move the DMA alignment code
into the Exynos driver source code.

Cc: Alim Akhtar <alim.akhtar@samsung.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20230921192335.676924-3-bvanassche@acm.org
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>
Tested-by: Alim Akhtar <alim.akhtar@samsung.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
9 months agoscsi: ufs: core: Remove request tag range checks
Bart Van Assche [Thu, 21 Sep 2023 19:22:46 +0000 (12:22 -0700)]
scsi: ufs: core: Remove request tag range checks

The block layer core guarantees that tag numbers are in the expected
range. Hence remove the statements that check this. This patch suppresses
Coverity warnings about left shifts with a negative right hand operand.
The following commit originally introduced request tag range checks:
14497328b6a6 ("scsi: ufs: verify command tag validity").

Cc: daejun7.park@samsung.com
Cc: John Garry <john.g.garry@oracle.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20230921192335.676924-2-bvanassche@acm.org
Reviewed-by: John Garry <john.g.garry@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
9 months agoscsi: target: Remove the references to http://www.linux-iscsi.org/
Bart Van Assche [Wed, 20 Sep 2023 20:00:19 +0000 (13:00 -0700)]
scsi: target: Remove the references to linux-iscsi.org/

The website http://www.linux-iscsi.org/ disappeared more than a year ago.
DNS records have been removed for linux-iscsi.org. The company that
sponsored this website (Datera; formerly called Rising Tide) has been
liquidated in early 2021 according to
https://blocksandfiles.com/2021/03/19/datera-is-being-liquidated/.  Since
it is unlikely that the website http://www.linux-iscsi.org/ will be
restored, remove the references to that website.

Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20230920200232.3721784-2-bvanassche@acm.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
9 months agoscsi: ibmvfc: Add protocol field to target structure
Tyrel Datwyler [Thu, 21 Sep 2023 22:54:35 +0000 (17:54 -0500)]
scsi: ibmvfc: Add protocol field to target structure

Add a per target protocol field so target code can determine correct
protocol specific actions as well as identify the correct channel group
target list.

Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
Link: https://lore.kernel.org/r/20230921225435.3537728-12-tyreld@linux.ibm.com
Reviewed-by: Brian King <brking@linux.vnet.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
9 months agoscsi: ibmvfc: Make discovery buffer per protocol channel group
Tyrel Datwyler [Thu, 21 Sep 2023 22:54:34 +0000 (17:54 -0500)]
scsi: ibmvfc: Make discovery buffer per protocol channel group

The target discovery buffer that the VIOS populates with targets is
currently a host adapter field. To facilitate the discovery of NVMe targets
as well as SCSI another discovery buffer is required. Move the discovery
buffer out of the host struct and into the ibmvfc_channels struct so that
each channels instance for a given protocol has its own discovery buffer.

Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
Link: https://lore.kernel.org/r/20230921225435.3537728-11-tyreld@linux.ibm.com
Reviewed-by: Brian King <brking@linux.vnet.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
9 months agoscsi: ibmvfc: Add protocol field to ibmvfc_channels
Tyrel Datwyler [Thu, 21 Sep 2023 22:54:33 +0000 (17:54 -0500)]
scsi: ibmvfc: Add protocol field to ibmvfc_channels

There are cases in the generic code where protocol specific configuration
or actions may need to be taken. Add a protocol field to struct
ibmvfc_channels and initial IBMVFC_PROTO_[SCSI/NVME] definitions.

Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
Link: https://lore.kernel.org/r/20230921225435.3537728-10-tyreld@linux.ibm.com
Reviewed-by: Brian King <brking@linux.vnet.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
9 months agoscsi: ibmvfc: Make channel allocation generic
Tyrel Datwyler [Thu, 21 Sep 2023 22:54:32 +0000 (17:54 -0500)]
scsi: ibmvfc: Make channel allocation generic

With the coming of NVMeoF support the driver will need to also allocate
channels for NVMe. Implement generic channel allocation wrappers that can
be used for both SCSI and NVMeoF protocol setup.

Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
Link: https://lore.kernel.org/r/20230921225435.3537728-9-tyreld@linux.ibm.com
Reviewed-by: Brian King <brking@linux.vnet.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>