Hi Alexey,

On 2026-09-18T06:35:41, Alexey Charkov <[email protected]> wrote:
> scsi: repeat an INQUIRY that a unit attention interrupted
>
> A unit reports the power-on unit attention to the first command it sees.
> For an ordinary logical unit that lands on the TEST UNIT READY, which is
> already retried, but a UFS boot well known unit reports it to the INQUIRY
> and so was written off as absent.

Not quite. My understanding of SPC is that INQUIRY (like REPORT LUNS
and REQUEST SENSE) is processed without reporting a pending unit
attention, which is why it normally lands on the TEST UNIT READY. So a
unit which answers INQUIRY with a unit attention is deviating from the
spec.

Linux handles the same thing in scsi_probe_lun() with a comment that
INQUIRY should not yield UNIT_ATTENTION but many buggy devices do so
anyway. Please can you reword this to say that it is a quirk, mention
which device(s) you see it on, and reference the Linux behaviour?

Since you are changing this, please use present tense ('is written off').

>
> Retry only for a unit attention, since a scan that walks a wide LUN range
> would otherwise pay three times over for every unit that is not there.
>
> Signed-off-by: Alexey Charkov <[email protected]>
>
> drivers/scsi/scsi.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 49 insertions(+), 5 deletions(-)

> diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
> @@ -467,6 +467,38 @@ static void scsi_init_dev_desc_priv(struct blk_desc 
> *dev_desc)
> +static bool scsi_unit_attention(struct scsi_cmd *pccb)
> +{
> +     u8 key;
> +
> +     if (pccb->sensedatalen < 3)
> +             return false;

After patch 1 only UFS fills in the sense data, so this is a nop for
every other controller. That seems fine, but please can you mention in
the function comment that the driver must provide sense data for the
retry to happen?

Please can you add a test for this? The sandbox emulator in
scsi_emul.c could report a unit attention to the first INQUIRY, with
sandbox_scsi passing the sense data back, so that test/dm/scsi.c
covers the retry path.

> diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
> @@ -490,11 +522,19 @@ static int scsi_detect_dev(struct udevice *dev, int 
> target, int lun,
> +     /*
> +      * A unit reports the power-on unit attention to the first command it
> +      * sees, so give it a couple of chances to get that out of the way.
> +      */
> +     for (count = 0; count < 3; count++) {

As with the commit message, please can you reword this to say that
some units (wrongly) report the unit attention to an INQUIRY?

BTW I think Linux only retries here for ASC 0x28 and 0x29
(not-ready-to-ready and power-on/reset), whereas this retries on any
unit attention. With a limit of three tries I suspect that is fine,
but it might be worth matching Linux. What do you think?

Regards,
Simon

Reply via email to