[PATCH v3 03/11] scsi: mpt3sas: Requeue topology events only for busy devices

From: Jeff Layton

Date: Wed Nov 18 2026 - 18:10:27 EST


Since commit ad5957193107 ("scsi: mpt3sas: Add firmware event requeue
support for busy devices"), _scsih_sas_topology_change_event() requeues
the event whenever _scsih_add_device() returns non-zero. It retries the
event every second. But _scsih_add_device() returns 1 only for a busy
device. It returns -1 when it cannot add the device at all. This occurs
when:

- the driver cannot read the SAS Device Page 0 of the device
- the device is not an end device, or is not present
- discovery reported an access problem
- the device is already added

None of these conditions clear with time, and nothing limits the
number of retries. In a stress test, the driver retried the add of a
device that was not present 249 times.

A requeued event keeps the handle and phy number from its original
report. Meanwhile, the handle may go to another device, because a host
reset assigns all handles again. In one stress run, a requeued add
first ran after a host reset. At that time, its handle was not in use.
Thus the read of SAS Device Page 0 failed, and the driver requeued the
event. One second later, at the retry, a device that was returning on
another phy had that handle.

The retry then makes mpt3sas_transport_update_links() record the SAS
address of that device on the phy of the event. The add of the device
then makes _transport_sanity_check() delete the port of the drive on
that phy. Thus the driver removed the drive, although the drive never
disappeared.

When _scsih_add_device() cannot add the device, return 0, as
_scsih_pcie_add_device() does. Then the driver retries only a busy
device. Some failures of the page read do clear with time:

- -EAGAIN, when no internal command is free or after a reset
- an IOC status of BUSY or INSUFFICIENT_RESOURCES

Continue to retry these failures, up to command_retry_count times, as
for a busy device. This change also prevents a spin on such a device
in the loops that call _scsih_add_device() after a host reset.

Fixes: ad5957193107 ("scsi: mpt3sas: Add firmware event requeue support for busy devices")
Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
---
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index b455b7e5d8f3..2d98fcb8e135 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -8509,7 +8509,9 @@ _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
*
* Creating end device object, stored in ioc->sas_device_list.
*
- * Return: 0 for success, non-zero for failure.
+ * Return: 1 if adding the device should be retried: it is busy, or
+ * reading its SAS Device Page 0 failed in a way that can clear with time.
+ * 0 otherwise.
*/
static int
_scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 retry_count,
@@ -8525,12 +8527,15 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 retry_count,
u32 device_info;
u8 connector_name[5];
u8 port_id;
+ int r;

- if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
- MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
+ r = mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
+ MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle);
+ if (r) {
ioc_err(ioc, "failure at %s:%d/%s()!\n",
__FILE__, __LINE__, __func__);
- return -1;
+ /* e.g. no free internal command, or a reset intervened */
+ return r == -EAGAIN && retry_count < command_retry_count;
}

ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
@@ -8538,13 +8543,15 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 retry_count,
if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
ioc_err(ioc, "failure at %s:%d/%s()!\n",
__FILE__, __LINE__, __func__);
- return -1;
+ return (ioc_status == MPI2_IOCSTATUS_BUSY ||
+ ioc_status == MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES) &&
+ retry_count < command_retry_count;
}

/* check if this is end device */
device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
if (!(_scsih_is_end_device(device_info)))
- return -1;
+ return 0;
set_bit(handle, ioc->pend_os_device_add);
sas_address = le64_to_cpu(sas_device_pg0.SASAddress);

@@ -8553,13 +8560,13 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 retry_count,
MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
ioc_err(ioc, "device is not present handle(0x04%x)!!!\n",
handle);
- return -1;
+ return 0;
}

/* check if there were any issues with discovery */
if (_scsih_check_access_status(ioc, sas_address, handle,
sas_device_pg0.AccessStatus))
- return -1;
+ return 0;

port_id = sas_device_pg0.PhysicalPort;
sas_device = mpt3sas_get_sdev_by_addr(ioc,
@@ -8567,7 +8574,7 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 retry_count,
if (sas_device) {
clear_bit(handle, ioc->pend_os_device_add);
sas_device_put(sas_device);
- return -1;
+ return 0;
}

if (sas_device_pg0.EnclosureHandle) {

--
2.56.1