diff mbox series

[1/4] scsi: Fix a bunch of SCSI definitions.

Message ID 20231029-usb-fixes-3-v1-1-0153210a7f55@marcan.st
State New
Delegated to: Marek Vasut
Headers show
Series USB fixes: Mass Storage bugs & 64bit support | expand

Commit Message

Hector Martin Oct. 29, 2023, 7:23 a.m. UTC
0x9e isn't Read Capacity, it's a service action and the read capacity
command is a subcommand.

READ16 is not 0x48, it's 0x88. 0x48 is SANITIZE and that sounds like we
might have been destroying data instead of reading data. No bueno.

Signed-off-by: Hector Martin <marcan@marcan.st>
---
 drivers/ata/ahci.c  | 9 ++++++---
 drivers/scsi/scsi.c | 4 ++--
 include/scsi.h      | 8 ++++++--
 3 files changed, 14 insertions(+), 7 deletions(-)

Comments

Marek Vasut Oct. 29, 2023, 12:07 p.m. UTC | #1
On 10/29/23 08:23, Hector Martin wrote:
> 0x9e isn't Read Capacity, it's a service action and the read capacity
> command is a subcommand.
> 
> READ16 is not 0x48, it's 0x88. 0x48 is SANITIZE and that sounds like we
> might have been destroying data instead of reading data. No bueno.
> 
> Signed-off-by: Hector Martin <marcan@marcan.st>
> ---
>   drivers/ata/ahci.c  | 9 ++++++---
>   drivers/scsi/scsi.c | 4 ++--
>   include/scsi.h      | 8 ++++++--
>   3 files changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> index 2062197afcd3..b252e9e525db 100644
> --- a/drivers/ata/ahci.c
> +++ b/drivers/ata/ahci.c
> @@ -906,15 +906,18 @@ static int ahci_scsi_exec(struct udevice *dev, struct scsi_cmd *pccb)
>   	case SCSI_RD_CAPAC10:
>   		ret = ata_scsiop_read_capacity10(uc_priv, pccb);
>   		break;
> -	case SCSI_RD_CAPAC16:
> -		ret = ata_scsiop_read_capacity16(uc_priv, pccb);
> -		break;
>   	case SCSI_TST_U_RDY:
>   		ret = ata_scsiop_test_unit_ready(uc_priv, pccb);
>   		break;
>   	case SCSI_INQUIRY:
>   		ret = ata_scsiop_inquiry(uc_priv, pccb);
>   		break;
> +	case SCSI_SRV_ACTION_IN:
> +		if ((pccb->cmd[1] & 0x1f) == SCSI_SAI_RD_CAPAC16) {
> +			ret = ata_scsiop_read_capacity16(uc_priv, pccb);
> +			break;
> +		}

Would it make sense to add an else branch here and report unknown 
subcommand there ?

With that:
Reviewed-by: Marek Vasut <marex@denx.de>
diff mbox series

Patch

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 2062197afcd3..b252e9e525db 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -906,15 +906,18 @@  static int ahci_scsi_exec(struct udevice *dev, struct scsi_cmd *pccb)
 	case SCSI_RD_CAPAC10:
 		ret = ata_scsiop_read_capacity10(uc_priv, pccb);
 		break;
-	case SCSI_RD_CAPAC16:
-		ret = ata_scsiop_read_capacity16(uc_priv, pccb);
-		break;
 	case SCSI_TST_U_RDY:
 		ret = ata_scsiop_test_unit_ready(uc_priv, pccb);
 		break;
 	case SCSI_INQUIRY:
 		ret = ata_scsiop_inquiry(uc_priv, pccb);
 		break;
+	case SCSI_SRV_ACTION_IN:
+		if ((pccb->cmd[1] & 0x1f) == SCSI_SAI_RD_CAPAC16) {
+			ret = ata_scsiop_read_capacity16(uc_priv, pccb);
+			break;
+		}
+		/* Fallthrough */
 	default:
 		printf("Unsupport SCSI command 0x%02x\n", pccb->cmd[0]);
 		return -ENOTSUPP;
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index d7b33010e469..f2c828eb305e 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -380,8 +380,8 @@  static int scsi_read_capacity(struct udevice *dev, struct scsi_cmd *pccb,
 
 	/* Read capacity (10) was insufficient. Use read capacity (16). */
 	memset(pccb->cmd, '\0', sizeof(pccb->cmd));
-	pccb->cmd[0] = SCSI_RD_CAPAC16;
-	pccb->cmd[1] = 0x10;
+	pccb->cmd[0] = SCSI_SRV_ACTION_IN;
+	pccb->cmd[1] = SCSI_SAI_RD_CAPAC16;
 	pccb->cmdlen = 16;
 	pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */
 
diff --git a/include/scsi.h b/include/scsi.h
index b47c7463c1d6..89e268586477 100644
--- a/include/scsi.h
+++ b/include/scsi.h
@@ -141,10 +141,9 @@  struct scsi_cmd {
 #define SCSI_MED_REMOVL	0x1E		/* Prevent/Allow medium Removal (O) */
 #define SCSI_READ6		0x08		/* Read 6-byte (MANDATORY) */
 #define SCSI_READ10		0x28		/* Read 10-byte (MANDATORY) */
-#define SCSI_READ16	0x48
+#define SCSI_READ16	0x88		/* Read 16-byte */
 #define SCSI_RD_CAPAC	0x25		/* Read Capacity (MANDATORY) */
 #define SCSI_RD_CAPAC10	SCSI_RD_CAPAC	/* Read Capacity (10) */
-#define SCSI_RD_CAPAC16	0x9e		/* Read Capacity (16) */
 #define SCSI_RD_DEFECT	0x37		/* Read Defect Data (O) */
 #define SCSI_READ_LONG	0x3E		/* Read Long (O) */
 #define SCSI_REASS_BLK	0x07		/* Reassign Blocks (O) */
@@ -158,15 +157,20 @@  struct scsi_cmd {
 #define SCSI_SEEK10		0x2B		/* Seek 10-Byte (O) */
 #define SCSI_SEND_DIAG	0x1D		/* Send Diagnostics (MANDATORY) */
 #define SCSI_SET_LIMIT	0x33		/* Set Limits (O) */
+#define SCSI_SRV_ACTION_IN	0x9E	/* Service Action In */
+#define SCSI_SRV_ACTION_OUT	0x9F	/* Service Action Out */
 #define SCSI_START_STP	0x1B		/* Start/Stop Unit (O) */
 #define SCSI_SYNC_CACHE	0x35		/* Synchronize Cache (O) */
 #define SCSI_VERIFY		0x2F		/* Verify (O) */
 #define SCSI_WRITE6		0x0A		/* Write 6-Byte (MANDATORY) */
 #define SCSI_WRITE10	0x2A		/* Write 10-Byte (MANDATORY) */
+#define SCSI_WRITE16	0x8A		/* Write 16-byte */
 #define SCSI_WRT_VERIFY	0x2E		/* Write and Verify (O) */
 #define SCSI_WRITE_LONG	0x3F		/* Write Long (O) */
 #define SCSI_WRITE_SAME	0x41		/* Write Same (O) */
 
+#define SCSI_SAI_RD_CAPAC16	0x10	/* Service Action: Read Capacity (16) */
+
 /**
  * struct scsi_plat - stores information about SCSI controller
  *