public inbox for linux-ide@vger.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Shaun Tancheff <shaun@tancheff.com>,
	linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Tejun Heo <tj@kernel.org>, Christoph Hellwig <hch@lst.de>,
	Tom Yan <tom.ty89@gmail.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Damien Le Moal <damien.lemoal@hgst.com>,
	Josh Bingaman <josh.bingaman@seagate.com>,
	Hannes Reinecke <hare@suse.com>,
	Shaun Tancheff <shaun.tancheff@seagate.com>
Subject: Re: [PATCH v6 3/4] SCT Write Same / DSM Trim
Date: Mon, 22 Aug 2016 08:30:58 +0200	[thread overview]
Message-ID: <0c9c5a80-813b-31f0-355d-2e08e452dd01@suse.de> (raw)
In-Reply-To: <20160822042321.24367-4-shaun@tancheff.com>

On 08/22/2016 06:23 AM, Shaun Tancheff wrote:
> Correct handling of devices with sector_size other that 512 bytes.
> 
> Signed-off-by: Shaun Tancheff <shaun.tancheff@seagate.com>
> ---
> In the case of a 4Kn device sector_size it is possible to describe a much
> larger DSM Trim than the current fixed default of 512 bytes.
> 
> This patch assumes the minimum descriptor is sector_size and fills out
> the descriptor accordingly.
> 
> The ACS-2 specification is quite clear that the DSM command payload is
> sized as number of 512 byte transfers so a 4Kn device will operate
> correctly without this patch.
> 
Can you please reshuffle the description to have the 'Signed-off-by'
line following the entire description?
This makes things easier to read and avoid the last part of the
description being killed by overzealous patch programs.
THX.

> v5:
>  - Added support for a sector_size descriptor other than 512 bytes.
> 
>  drivers/ata/libata-scsi.c | 85 +++++++++++++++++++++++++++++++----------------
>  1 file changed, 57 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> index ebf1a04..37f456e 100644
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
> @@ -3283,7 +3283,7 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc)
>  /**
>   * ata_format_dsm_trim_descr() - SATL Write Same to DSM Trim
>   * @cmd: SCSI command being translated
> - * @num: Maximum number of entries (nominally 64).
> + * @trmax: Maximum number of entries that will fit in sector_size bytes.
>   * @sector: Starting sector
>   * @count: Total Range of request in logical sectors
>   *
> @@ -3298,63 +3298,80 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc)
>   *  LBA's should be sorted order and not overlap.
>   *
>   * NOTE: this is the same format as ADD LBA(S) TO NV CACHE PINNED SET
> + *
> + * Return: Number of bytes copied into sglist.
>   */
> -static unsigned int ata_format_dsm_trim_descr(struct scsi_cmnd *cmd, u32 num,
> -					      u64 sector, u32 count)
> +static size_t ata_format_dsm_trim_descr(struct scsi_cmnd *cmd, u32 trmax,
> +					u64 sector, u32 count)
>  {
> -	__le64 *buffer;
> -	u32 i = 0, used_bytes;
> +	struct scsi_device *sdp = cmd->device;
> +	size_t len = sdp->sector_size;
> +	size_t r;
> +	__le64 *buf;
> +	u32 i = 0;
>  	unsigned long flags;
>  
> -	BUILD_BUG_ON(512 > ATA_SCSI_RBUF_SIZE);
> +	WARN_ON(len > ATA_SCSI_RBUF_SIZE);
> +
> +	if (len > ATA_SCSI_RBUF_SIZE)
> +		len = ATA_SCSI_RBUF_SIZE;
>  
>  	spin_lock_irqsave(&ata_scsi_rbuf_lock, flags);
> -	buffer = ((void *)ata_scsi_rbuf);
> -	while (i < num) {
> +	buf = ((void *)ata_scsi_rbuf);
> +	memset(buf, 0, len);
> +	while (i < trmax) {
>  		u64 entry = sector |
>  			((u64)(count > 0xffff ? 0xffff : count) << 48);
> -		buffer[i++] = __cpu_to_le64(entry);
> +		buf[i++] = __cpu_to_le64(entry);
>  		if (count <= 0xffff)
>  			break;
>  		count -= 0xffff;
>  		sector += 0xffff;
>  	}
> -
> -	used_bytes = ALIGN(i * 8, 512);
> -	memset(buffer + i, 0, used_bytes - i * 8);
> -	sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd), buffer, 512);
> +	r = sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd), buf, len);
>  	spin_unlock_irqrestore(&ata_scsi_rbuf_lock, flags);
>  
> -	return used_bytes;
> +	return r;
>  }
>  
>  /**
>   * ata_format_dsm_trim_descr() - SATL Write Same to ATA SCT Write Same
>   * @cmd: SCSI command being translated
>   * @lba: Starting sector
> - * @num: Number of logical sectors to be zero'd.
> + * @num: Number of sectors to be zero'd.
>   *
> - * Rewrite the WRITE SAME descriptor to be an SCT Write Same formatted
> + * Rewrite the WRITE SAME payload to be an SCT Write Same formatted
>   * descriptor.
>   * NOTE: Writes a pattern (0's) in the foreground.
> - *       Large write-same requents can timeout.
> + *
> + * Return: Number of bytes copied into sglist.
>   */
> -static void ata_format_sct_write_same(struct scsi_cmnd *cmd, u64 lba, u64 num)
> +static size_t ata_format_sct_write_same(struct scsi_cmnd *cmd, u64 lba, u64 num)
>  {
> -	u16 *sctpg;
> +	struct scsi_device *sdp = cmd->device;
> +	size_t len = sdp->sector_size;
> +	size_t r;
> +	u16 *buf;
>  	unsigned long flags;
>  
>  	spin_lock_irqsave(&ata_scsi_rbuf_lock, flags);
> -	sctpg = ((void *)ata_scsi_rbuf);
> +	buf = ((void *)ata_scsi_rbuf);
> +
> +	put_unaligned_le16(0x0002,  &buf[0]); /* SCT_ACT_WRITE_SAME */
> +	put_unaligned_le16(0x0101,  &buf[1]); /* WRITE PTRN FG */
> +	put_unaligned_le64(lba,     &buf[2]);
> +	put_unaligned_le64(num,     &buf[6]);
> +	put_unaligned_le32(0u,      &buf[10]); /* pattern */
> +
> +	WARN_ON(len > ATA_SCSI_RBUF_SIZE);
>  
> -	put_unaligned_le16(0x0002,  &sctpg[0]); /* SCT_ACT_WRITE_SAME */
> -	put_unaligned_le16(0x0101,  &sctpg[1]); /* WRITE PTRN FG */
> -	put_unaligned_le64(lba,     &sctpg[2]);
> -	put_unaligned_le64(num,     &sctpg[6]);
> -	put_unaligned_le32(0u,      &sctpg[10]);
> +	if (len > ATA_SCSI_RBUF_SIZE)
> +		len = ATA_SCSI_RBUF_SIZE;
>  
> -	sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd), sctpg, 512);
> +	r = sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd), buf, len);
>  	spin_unlock_irqrestore(&ata_scsi_rbuf_lock, flags);
> +
> +	return r;
>  }
>  
>  /**
> @@ -3371,11 +3388,13 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc)
>  {
>  	struct ata_taskfile *tf = &qc->tf;
>  	struct scsi_cmnd *scmd = qc->scsicmd;
> +	struct scsi_device *sdp = scmd->device;
> +	size_t len = sdp->sector_size;
>  	struct ata_device *dev = qc->dev;
>  	const u8 *cdb = scmd->cmnd;
>  	u64 block;
>  	u32 n_block;
> -	const u32 trmax = ATA_MAX_TRIM_RNUM;
> +	const u32 trmax = len >> 3;
>  	u32 size;
>  	u16 fp;
>  	u8 bp = 0xff;
> @@ -3420,8 +3439,16 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc)
>  	if (!scsi_sg_count(scmd))
>  		goto invalid_param_len;
>  
> +	/*
> +	 * size must match sector size in bytes
> +	 * For DATA SET MANAGEMENT TRIM in ACS-2 nsect (aka count)
> +	 * is defined as number of 512 byte blocks to be transferred.
> +	 */
>  	if (unmap) {
>  		size = ata_format_dsm_trim_descr(scmd, trmax, block, n_block);
> +		if (size != len)
> +			goto invalid_param_len;
> +
>  		if (ata_ncq_enabled(dev) && ata_fpdma_dsm_supported(dev)) {
>  			/* Newer devices support queued TRIM commands */
>  			tf->protocol = ATA_PROT_NCQ;
> @@ -3441,7 +3468,9 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc)
>  			tf->command = ATA_CMD_DSM;
>  		}
>  	} else {
> -		ata_format_sct_write_same(scmd, block, n_block);
> +		size = ata_format_sct_write_same(scmd, block, n_block);
> +		if (size != len)
> +			goto invalid_param_len;
>  
>  		tf->hob_feature = 0;
>  		tf->feature = 0;
> 
Why is this not folded into the previous patches?
This mostly patches code which you've already modified and/or initiated,
right?

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare@suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)

  reply	other threads:[~2016-08-22  6:31 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-22  4:23 [PATCH v6 0/4] SCT Write Same Shaun Tancheff
2016-08-22  4:23 ` [PATCH v6 1/4] libata: Safely overwrite attached page in WRITE SAME xlat Shaun Tancheff
2016-08-22  6:27   ` Hannes Reinecke
2016-08-22 19:27   ` Tom Yan
2016-08-22 19:51     ` Shaun Tancheff
2016-08-22 20:12       ` Tom Yan
2016-08-22 21:20   ` Tom Yan
2016-08-22 22:00     ` Shaun Tancheff
2016-08-22 23:49       ` Tom Yan
2016-08-23  1:01         ` Shaun Tancheff
2016-08-23  5:26           ` Tom Yan
2016-08-23  6:20             ` Shaun Tancheff
2016-08-23  7:53               ` Tom Yan
2016-08-23  8:42                 ` Shaun Tancheff
2016-08-23  9:04                   ` Tom Yan
2016-08-24  3:33                 ` Martin K. Petersen
2016-08-24  5:31                   ` Tom Yan
2016-08-24 21:28                     ` Shaun Tancheff
2016-08-25  6:31                       ` Tom Yan
2016-08-25  7:18                         ` Shaun Tancheff
2016-08-22  4:23 ` [PATCH v6 2/4] Add support for SCT Write Same Shaun Tancheff
2016-08-22  6:27   ` Hannes Reinecke
2016-08-22 19:20   ` Tom Yan
2016-08-22 19:43     ` Shaun Tancheff
2016-08-22 20:14       ` Tom Yan
2016-08-22 22:07         ` Shaun Tancheff
2016-08-22 23:09           ` Tom Yan
2016-08-23  0:36             ` Shaun Tancheff
2016-08-23  5:55               ` Tom Yan
2016-08-23  6:11                 ` Shaun Tancheff
2016-08-23  7:57                   ` Tom Yan
2016-08-23 10:37   ` Tom Yan
2016-08-23 10:56     ` Shaun Tancheff
2016-08-24  5:57       ` Tom Yan
2016-08-24  6:10         ` Tom Yan
2016-08-24 22:04           ` Shaun Tancheff
2016-08-25  6:23             ` Tom Yan
2016-08-25  7:31               ` Shaun Tancheff
2016-08-22  4:23 ` [PATCH v6 3/4] SCT Write Same / DSM Trim Shaun Tancheff
2016-08-22  6:30   ` Hannes Reinecke [this message]
2016-08-24 18:08     ` [PATCH v6 3/4 RESEND] " Shaun Tancheff
2016-08-25  7:01       ` Tom Yan
2016-08-25  8:03         ` Shaun Tancheff
2016-08-25  9:30           ` Tom Yan
2016-08-22  8:31   ` [PATCH v6 3/4] " Tom Yan
2016-08-22  8:33     ` Tom Yan
2016-08-22 15:04       ` Shaun Tancheff
2016-08-22 17:02         ` Tom Yan
2016-08-22 18:00           ` Shaun Tancheff
2016-08-22 18:52             ` Tom Yan
2016-08-22 20:57               ` Tom Yan
2016-08-22  4:23 ` [PATCH v6 4/4] SCT Write Same handle ATA_DFLAG_PIO Shaun Tancheff
2016-08-22  6:31   ` Hannes Reinecke
2016-08-22  6:32 ` [PATCH v6 0/4] SCT Write Same Hannes Reinecke
2016-08-25 15:28 ` Tejun Heo

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=0c9c5a80-813b-31f0-355d-2e08e452dd01@suse.de \
    --to=hare@suse.de \
    --cc=damien.lemoal@hgst.com \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=josh.bingaman@seagate.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=shaun.tancheff@seagate.com \
    --cc=shaun@tancheff.com \
    --cc=tj@kernel.org \
    --cc=tom.ty89@gmail.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