Skip to content

Commit 63ccc19

Browse files
Christoph Hellwightejun
authored andcommitted
libata: remove SCT WRITE SAME support
This was already disabled a while ago because it caused I/O errors, and it's severly getting into the way of the discard / write zeroes rework. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent c6ade20 commit 63ccc19

2 files changed

Lines changed: 29 additions & 108 deletions

File tree

‎drivers/ata/libata-scsi.c‎

Lines changed: 29 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,46 +3392,6 @@ static size_t ata_format_dsm_trim_descr(struct scsi_cmnd *cmd, u32 trmax,
33923392
return r;
33933393
}
33943394

3395-
/**
3396-
* ata_format_dsm_trim_descr() - SATL Write Same to ATA SCT Write Same
3397-
* @cmd: SCSI command being translated
3398-
* @lba: Starting sector
3399-
* @num: Number of sectors to be zero'd.
3400-
*
3401-
* Rewrite the WRITE SAME payload to be an SCT Write Same formatted
3402-
* descriptor.
3403-
* NOTE: Writes a pattern (0's) in the foreground.
3404-
*
3405-
* Return: Number of bytes copied into sglist.
3406-
*/
3407-
static size_t ata_format_sct_write_same(struct scsi_cmnd *cmd, u64 lba, u64 num)
3408-
{
3409-
struct scsi_device *sdp = cmd->device;
3410-
size_t len = sdp->sector_size;
3411-
size_t r;
3412-
u16 *buf;
3413-
unsigned long flags;
3414-
3415-
spin_lock_irqsave(&ata_scsi_rbuf_lock, flags);
3416-
buf = ((void *)ata_scsi_rbuf);
3417-
3418-
put_unaligned_le16(0x0002, &buf[0]); /* SCT_ACT_WRITE_SAME */
3419-
put_unaligned_le16(0x0101, &buf[1]); /* WRITE PTRN FG */
3420-
put_unaligned_le64(lba, &buf[2]);
3421-
put_unaligned_le64(num, &buf[6]);
3422-
put_unaligned_le32(0u, &buf[10]); /* pattern */
3423-
3424-
WARN_ON(len > ATA_SCSI_RBUF_SIZE);
3425-
3426-
if (len > ATA_SCSI_RBUF_SIZE)
3427-
len = ATA_SCSI_RBUF_SIZE;
3428-
3429-
r = sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd), buf, len);
3430-
spin_unlock_irqrestore(&ata_scsi_rbuf_lock, flags);
3431-
3432-
return r;
3433-
}
3434-
34353395
/**
34363396
* ata_scsi_write_same_xlat() - SATL Write Same to ATA SCT Write Same
34373397
* @qc: Command to be translated
@@ -3476,26 +3436,17 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc)
34763436
}
34773437
scsi_16_lba_len(cdb, &block, &n_block);
34783438

3479-
if (unmap) {
3480-
/* If trim is not enabled the cmd is invalid. */
3481-
if ((dev->horkage & ATA_HORKAGE_NOTRIM) ||
3482-
!ata_id_has_trim(dev->id)) {
3483-
fp = 1;
3484-
bp = 3;
3485-
goto invalid_fld;
3486-
}
3487-
/* If the request is too large the cmd is invalid */
3488-
if (n_block > 0xffff * trmax) {
3489-
fp = 2;
3490-
goto invalid_fld;
3491-
}
3492-
} else {
3493-
/* If write same is not available the cmd is invalid */
3494-
if (!ata_id_sct_write_same(dev->id)) {
3495-
fp = 1;
3496-
bp = 3;
3497-
goto invalid_fld;
3498-
}
3439+
if (!unmap ||
3440+
(dev->horkage & ATA_HORKAGE_NOTRIM) ||
3441+
!ata_id_has_trim(dev->id)) {
3442+
fp = 1;
3443+
bp = 3;
3444+
goto invalid_fld;
3445+
}
3446+
/* If the request is too large the cmd is invalid */
3447+
if (n_block > 0xffff * trmax) {
3448+
fp = 2;
3449+
goto invalid_fld;
34993450
}
35003451

35013452
/*
@@ -3510,49 +3461,28 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc)
35103461
* For DATA SET MANAGEMENT TRIM in ACS-2 nsect (aka count)
35113462
* is defined as number of 512 byte blocks to be transferred.
35123463
*/
3513-
if (unmap) {
3514-
size = ata_format_dsm_trim_descr(scmd, trmax, block, n_block);
3515-
if (size != len)
3516-
goto invalid_param_len;
35173464

3518-
if (ata_ncq_enabled(dev) && ata_fpdma_dsm_supported(dev)) {
3519-
/* Newer devices support queued TRIM commands */
3520-
tf->protocol = ATA_PROT_NCQ;
3521-
tf->command = ATA_CMD_FPDMA_SEND;
3522-
tf->hob_nsect = ATA_SUBCMD_FPDMA_SEND_DSM & 0x1f;
3523-
tf->nsect = qc->tag << 3;
3524-
tf->hob_feature = (size / 512) >> 8;
3525-
tf->feature = size / 512;
3465+
size = ata_format_dsm_trim_descr(scmd, trmax, block, n_block);
3466+
if (size != len)
3467+
goto invalid_param_len;
35263468

3527-
tf->auxiliary = 1;
3528-
} else {
3529-
tf->protocol = ATA_PROT_DMA;
3530-
tf->hob_feature = 0;
3531-
tf->feature = ATA_DSM_TRIM;
3532-
tf->hob_nsect = (size / 512) >> 8;
3533-
tf->nsect = size / 512;
3534-
tf->command = ATA_CMD_DSM;
3535-
}
3536-
} else {
3537-
size = ata_format_sct_write_same(scmd, block, n_block);
3538-
if (size != len)
3539-
goto invalid_param_len;
3469+
if (ata_ncq_enabled(dev) && ata_fpdma_dsm_supported(dev)) {
3470+
/* Newer devices support queued TRIM commands */
3471+
tf->protocol = ATA_PROT_NCQ;
3472+
tf->command = ATA_CMD_FPDMA_SEND;
3473+
tf->hob_nsect = ATA_SUBCMD_FPDMA_SEND_DSM & 0x1f;
3474+
tf->nsect = qc->tag << 3;
3475+
tf->hob_feature = (size / 512) >> 8;
3476+
tf->feature = size / 512;
35403477

3541-
tf->hob_feature = 0;
3542-
tf->feature = 0;
3543-
tf->hob_nsect = 0;
3544-
tf->nsect = 1;
3545-
tf->lbah = 0;
3546-
tf->lbam = 0;
3547-
tf->lbal = ATA_CMD_STANDBYNOW1;
3548-
tf->hob_lbah = 0;
3549-
tf->hob_lbam = 0;
3550-
tf->hob_lbal = 0;
3551-
tf->device = ATA_CMD_STANDBYNOW1;
3478+
tf->auxiliary = 1;
3479+
} else {
35523480
tf->protocol = ATA_PROT_DMA;
3553-
tf->command = ATA_CMD_WRITE_LOG_DMA_EXT;
3554-
if (unlikely(dev->flags & ATA_DFLAG_PIO))
3555-
tf->command = ATA_CMD_WRITE_LOG_EXT;
3481+
tf->hob_feature = 0;
3482+
tf->feature = ATA_DSM_TRIM;
3483+
tf->hob_nsect = (size / 512) >> 8;
3484+
tf->nsect = size / 512;
3485+
tf->command = ATA_CMD_DSM;
35563486
}
35573487

35583488
tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48 |
@@ -3627,10 +3557,6 @@ static unsigned int ata_scsiop_maint_in(struct ata_scsi_args *args, u8 *rbuf)
36273557
case START_STOP:
36283558
supported = 3;
36293559
break;
3630-
case WRITE_SAME_16:
3631-
if (!ata_id_sct_write_same(dev->id))
3632-
break;
3633-
/* fallthrough: if SCT ... only enable for ZBC */
36343560
case ZBC_IN:
36353561
case ZBC_OUT:
36363562
if (ata_id_zoned_cap(dev->id) ||

‎include/linux/ata.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -817,11 +817,6 @@ static inline bool ata_id_sct_error_recovery_ctrl(const u16 *id)
817817
return id[ATA_ID_SCT_CMD_XPORT] & (1 << 3) ? true : false;
818818
}
819819

820-
static inline bool ata_id_sct_write_same(const u16 *id)
821-
{
822-
return id[ATA_ID_SCT_CMD_XPORT] & (1 << 2) ? true : false;
823-
}
824-
825820
static inline bool ata_id_sct_long_sector_access(const u16 *id)
826821
{
827822
return id[ATA_ID_SCT_CMD_XPORT] & (1 << 1) ? true : false;

0 commit comments

Comments
 (0)