Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Niklas Cassel <Niklas.Cassel@wdc.com>
To: Damien Le Moal <dlemoal@kernel.org>
Cc: "Martin K . Petersen" <martin.petersen@oracle.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	John David Anglin <dave.anglin@bell.net>
Subject: Re: [PATCH] scsi: Do no try to probe for CDL on old drives
Date: Mon, 18 Sep 2023 19:51:35 +0000	[thread overview]
Message-ID: <ZQiqRXuygIWaUux8@x1-carbon> (raw)
In-Reply-To: <20230915022034.678121-1-dlemoal@kernel.org>

On Fri, Sep 15, 2023 at 11:20:34AM +0900, Damien Le Moal wrote:
> Some old drives (e.g. an Ultra320 SCSI disk as reported by John) do not
> seem to execute MAINTENANCE_IN / MI_REPORT_SUPPORTED_OPERATION_CODES
> commands correctly and hang when a non-zero service action is specified
> (one command format with service action case in scsi_report_opcode()).
> 
> Currently, CDL probing with scsi_cdl_check_cmd() is the only caller
> using a non zero service action for scsi_report_opcode(). To avoid
> issues with these old drives, do not attempt CDL probe if the device
> reports support for an SPC version lower than 5 (CDL was introduced in
> SPC-5). To keep things working with ATA devices which probe for the CDL
> T2A and T2B pages introduced with SPC-6, modify ata_scsiop_inq_std() to
> claim SPC-6 version compatibility for ATA drives supporting CDL.
> 
> SPC-6 standard version number is defined as Dh (= 13) in SPC-6 r09. Fix
> scsi_probe_lun() to correctly capture this value by changing the bit
> mask for the second byte of the INQUIRY response from 0x7 to 0xf.
> include/scsi/scsi.h is modified to add the definition SCSI_SPC_6 with
> the value 14 (Dh + 1). The missing definitions for the SCSI_SPC_4 and
> SCSI_SPC_5 versions are also added.
> 
> Reported-by: John David Anglin <dave.anglin@bell.net>
> Fixes: 624885209f31 ("scsi: core: Detect support for command duration limits")
> Cc: stable@vger.kernel.org
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
> ---
>  drivers/ata/libata-scsi.c |  3 +++
>  drivers/scsi/scsi.c       | 11 +++++++++++
>  drivers/scsi/scsi_scan.c  |  2 +-
>  include/scsi/scsi.h       |  3 +++
>  4 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> index 92ae4b4f30ac..7aa70af1fc07 100644
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
> @@ -1828,6 +1828,9 @@ static unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf)
>  		hdr[2] = 0x7; /* claim SPC-5 version compatibility */
>  	}
>  
> +	if (args->dev->flags & ATA_DFLAG_CDL)
> +		hdr[2] = 0xd; /* claim SPC-6 version compatibility */
> +
>  	memcpy(rbuf, hdr, sizeof(hdr));
>  	memcpy(&rbuf[8], "ATA     ", 8);
>  	ata_id_string(args->id, &rbuf[16], ATA_ID_PROD, 16);
> diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
> index d0911bc28663..89367c4bf0ef 100644
> --- a/drivers/scsi/scsi.c
> +++ b/drivers/scsi/scsi.c
> @@ -613,6 +613,17 @@ void scsi_cdl_check(struct scsi_device *sdev)
>  	bool cdl_supported;
>  	unsigned char *buf;
>  
> +	/*
> +	 * Support for CDL was defined in SPC-5. Ignore devices reporting an
> +	 * lower SPC version. This also avoids problems with old drives choking
> +	 * on MAINTENANCE_IN / MI_REPORT_SUPPORTED_OPERATION_CODES with a
> +	 * service action specified, as done in scsi_cdl_check_cmd().
> +	 */
> +	if (sdev->scsi_level < SCSI_SPC_5) {
> +		sdev->cdl_supported = 0;
> +		return;
> +	}
> +
>  	buf = kmalloc(SCSI_CDL_CHECK_BUF_LEN, GFP_KERNEL);
>  	if (!buf) {
>  		sdev->cdl_supported = 0;
> diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
> index 6650f63afec9..37dd6bbcffd3 100644
> --- a/drivers/scsi/scsi_scan.c
> +++ b/drivers/scsi/scsi_scan.c
> @@ -822,7 +822,7 @@ static int scsi_probe_lun(struct scsi_device *sdev, unsigned char *inq_result,
>  	 * device is attached at LUN 0 (SCSI_SCAN_TARGET_PRESENT) so
>  	 * non-zero LUNs can be scanned.
>  	 */
> -	sdev->scsi_level = inq_result[2] & 0x07;
> +	sdev->scsi_level = inq_result[2] & 0x0f;
>  	if (sdev->scsi_level >= 2 ||
>  	    (sdev->scsi_level == 1 && (inq_result[3] & 0x0f) == 1))
>  		sdev->scsi_level++;
> diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
> index ec093594ba53..4498f845b112 100644
> --- a/include/scsi/scsi.h
> +++ b/include/scsi/scsi.h
> @@ -157,6 +157,9 @@ enum scsi_disposition {
>  #define SCSI_3          4        /* SPC */
>  #define SCSI_SPC_2      5
>  #define SCSI_SPC_3      6
> +#define SCSI_SPC_4	7
> +#define SCSI_SPC_5	8
> +#define SCSI_SPC_6	14
>  
>  /*
>   * INQ PERIPHERAL QUALIFIERS
> -- 
> 2.41.0
> 

Reviewed-by: Niklas Cassel <niklas.cassel@wdc.com>

  parent reply	other threads:[~2023-09-18 19:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-15  2:20 [PATCH] scsi: Do no try to probe for CDL on old drives Damien Le Moal
2023-09-15 15:06 ` Bart Van Assche
2023-09-15 22:21   ` Damien Le Moal
2023-09-16 14:25     ` Bart Van Assche
2023-09-16  2:24 ` David Gow
2023-09-18 19:51 ` Niklas Cassel [this message]
2023-09-22  2:23 ` Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZQiqRXuygIWaUux8@x1-carbon \
    --to=niklas.cassel@wdc.com \
    --cc=dave.anglin@bell.net \
    --cc=dlemoal@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox