linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] scsi: sd: call SYNC 16 in place of SYNC 10 on ZBC devices
@ 2022-11-15  0:29 Shin'ichiro Kawasaki
  2022-11-26  0:21 ` Martin K. Petersen
  2022-12-01  3:45 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: Shin'ichiro Kawasaki @ 2022-11-15  0:29 UTC (permalink / raw)
  To: linux-scsi, Martin K . Petersen
  Cc: Christoph Hellwig, Damien Le Moal, Dmitry Fomichev,
	Shin'ichiro Kawasaki

ZBC Zoned Block Commands specification mandates SYNCHRONIZE CACHE (16)
for host-managed zoned block devices, but does not mandate SYNCHRONIZE
CACHE (10). Call SYNCHRONIZE CACHE (16) in place of SYNCHRONIZE CACHE
(10) to ensure that the command is always supported. For this purpose,
add use_16_for_sync flag to struct scsi_device in same manner as
use_16_for_rw flag.

To be precise, ZBC does not mandate SYNCHRONIZE CACHE (16) for host-
aware zoned block devices. However, modern devices should support 16
byte commands. Hence, call SYNCHRONIZE CACHE (16) on both types of ZBC
devices, host-aware and host-managed. Of note is that READ (16) and
WRITE (16) have same story and they are already called for both types of
ZBC devices before this change.

Another note is that this patch depends on the fix commit ea045fd344cb
("ata: libata-scsi: fix SYNCHRONIZE CACHE (16) command failure").

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Reviewed-by: Damien Le Moal <damien.lemoal@opendource.wdc.com>
---
Changes from v2:
* Rephrased commit message to reflect discussion on the list
* Modifed reference of dependent change in commit message from URL to git hash
* Added a Reviewed-by tag

Changes from v1:
* Dropped the first patch to relax check on host-aware devices
* Call SYNC 16 command on both host-aware and host-managed devices

 drivers/scsi/sd.c          | 16 ++++++++++++----
 drivers/scsi/sd_zbc.c      |  3 ++-
 include/scsi/scsi_device.h |  1 +
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index eb76ba055021..faa2b55d1a21 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1026,8 +1026,13 @@ static blk_status_t sd_setup_flush_cmnd(struct scsi_cmnd *cmd)
 	/* flush requests don't perform I/O, zero the S/G table */
 	memset(&cmd->sdb, 0, sizeof(cmd->sdb));
 
-	cmd->cmnd[0] = SYNCHRONIZE_CACHE;
-	cmd->cmd_len = 10;
+	if (cmd->device->use_16_for_sync) {
+		cmd->cmnd[0] = SYNCHRONIZE_CACHE_16;
+		cmd->cmd_len = 16;
+	} else {
+		cmd->cmnd[0] = SYNCHRONIZE_CACHE;
+		cmd->cmd_len = 10;
+	}
 	cmd->transfersize = 0;
 	cmd->allowed = sdkp->max_retries;
 
@@ -1587,9 +1592,12 @@ static int sd_sync_cache(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr)
 		sshdr = &my_sshdr;
 
 	for (retries = 3; retries > 0; --retries) {
-		unsigned char cmd[10] = { 0 };
+		unsigned char cmd[16] = { 0 };
 
-		cmd[0] = SYNCHRONIZE_CACHE;
+		if (sdp->use_16_for_sync)
+			cmd[0] = SYNCHRONIZE_CACHE_16;
+		else
+			cmd[0] = SYNCHRONIZE_CACHE;
 		/*
 		 * Leave the rest of the command zero to indicate
 		 * flush everything.
diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
index bd15624c6322..b163bf936acc 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -921,9 +921,10 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, u8 buf[SD_BUF_SIZE])
 		return 0;
 	}
 
-	/* READ16/WRITE16 is mandatory for ZBC disks */
+	/* READ16/WRITE16/SYNC16 is mandatory for ZBC devices */
 	sdkp->device->use_16_for_rw = 1;
 	sdkp->device->use_10_for_rw = 0;
+	sdkp->device->use_16_for_sync = 1;
 
 	if (!blk_queue_is_zoned(q)) {
 		/*
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index c36656d8ac6c..afd2986007a4 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -184,6 +184,7 @@ struct scsi_device {
 	unsigned no_report_opcodes:1;	/* no REPORT SUPPORTED OPERATION CODES */
 	unsigned no_write_same:1;	/* no WRITE SAME command */
 	unsigned use_16_for_rw:1; /* Use read/write(16) over read/write(10) */
+	unsigned use_16_for_sync:1;	/* Use sync (16) over sync (10) */
 	unsigned skip_ms_page_8:1;	/* do not use MODE SENSE page 0x08 */
 	unsigned skip_ms_page_3f:1;	/* do not use MODE SENSE page 0x3f */
 	unsigned skip_vpd_pages:1;	/* do not read VPD pages */
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] scsi: sd: call SYNC 16 in place of SYNC 10 on ZBC devices
  2022-11-15  0:29 [PATCH v3] scsi: sd: call SYNC 16 in place of SYNC 10 on ZBC devices Shin'ichiro Kawasaki
@ 2022-11-26  0:21 ` Martin K. Petersen
  2022-12-01  3:45 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2022-11-26  0:21 UTC (permalink / raw)
  To: Shin'ichiro Kawasaki
  Cc: linux-scsi, Martin K . Petersen, Christoph Hellwig,
	Damien Le Moal, Dmitry Fomichev


Shin'ichiro,

> ZBC Zoned Block Commands specification mandates SYNCHRONIZE CACHE (16)
> for host-managed zoned block devices, but does not mandate SYNCHRONIZE
> CACHE (10). Call SYNCHRONIZE CACHE (16) in place of SYNCHRONIZE CACHE
> (10) to ensure that the command is always supported. For this purpose,
> add use_16_for_sync flag to struct scsi_device in same manner as
> use_16_for_rw flag.

Applied to 6.2/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] scsi: sd: call SYNC 16 in place of SYNC 10 on ZBC devices
  2022-11-15  0:29 [PATCH v3] scsi: sd: call SYNC 16 in place of SYNC 10 on ZBC devices Shin'ichiro Kawasaki
  2022-11-26  0:21 ` Martin K. Petersen
@ 2022-12-01  3:45 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2022-12-01  3:45 UTC (permalink / raw)
  To: linux-scsi, Shin'ichiro Kawasaki
  Cc: Martin K . Petersen, Damien Le Moal, Dmitry Fomichev, Christoph Hellwig

On Tue, 15 Nov 2022 09:29:05 +0900, Shin'ichiro Kawasaki wrote:

> ZBC Zoned Block Commands specification mandates SYNCHRONIZE CACHE (16)
> for host-managed zoned block devices, but does not mandate SYNCHRONIZE
> CACHE (10). Call SYNCHRONIZE CACHE (16) in place of SYNCHRONIZE CACHE
> (10) to ensure that the command is always supported. For this purpose,
> add use_16_for_sync flag to struct scsi_device in same manner as
> use_16_for_rw flag.
> 
> [...]

Applied to 6.2/scsi-queue, thanks!

[1/1] scsi: sd: call SYNC 16 in place of SYNC 10 on ZBC devices
      https://git.kernel.org/mkp/scsi/c/42c590772886

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-01  3:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-15  0:29 [PATCH v3] scsi: sd: call SYNC 16 in place of SYNC 10 on ZBC devices Shin'ichiro Kawasaki
2022-11-26  0:21 ` Martin K. Petersen
2022-12-01  3:45 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).