Skip to content

Commit 1153393

Browse files
ipylypivdamien-lemoal
authored andcommitted
ata: libata-scsi: Do not set the INFORMATION field twice for ATA PT
For ATA PASS-THROUGH + fixed format sense data + NCQ autosense the INFORMATION sense data field is being written twice: - 1st write: (redundant) scsi_set_sense_information() sets the INFORMATION field to ATA LBA. This is incorrect for ATA PASS-THROUGH. - 2nd write: (correct) ata_scsi_set_passthru_sense_fields() sets the INFORMATION field to ATA ERROR/STATUS/DEVICE/COUNT(7:0) as per SAT spec. There is no user-visible issue because second write overwrites the incorrect data from the first write. This patch eliminates the reduntant write by moving the INFORMATION sense data field population logic to ata_scsi_qc_complete(). Signed-off-by: Igor Pylypiv <[email protected]> Reviewed-by: Niklas Cassel <[email protected]> Signed-off-by: Damien Le Moal <[email protected]>
1 parent 23a8e0d commit 1153393

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

drivers/ata/libata-sata.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,8 +1659,6 @@ void ata_eh_analyze_ncq_error(struct ata_link *link)
16591659
if (ata_scsi_sense_is_valid(sense_key, asc, ascq)) {
16601660
ata_scsi_set_sense(dev, qc->scsicmd, sense_key, asc,
16611661
ascq);
1662-
ata_scsi_set_sense_information(dev, qc->scsicmd,
1663-
&qc->result_tf);
16641662
qc->flags |= ATA_QCFLAG_SENSE_VALID;
16651663
}
16661664
}

drivers/ata/libata-scsi.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,21 @@ void ata_scsi_set_sense(struct ata_device *dev, struct scsi_cmnd *cmd,
216216
scsi_build_sense(cmd, d_sense, sk, asc, ascq);
217217
}
218218

219-
void ata_scsi_set_sense_information(struct ata_device *dev,
220-
struct scsi_cmnd *cmd,
221-
const struct ata_taskfile *tf)
219+
static void ata_scsi_set_sense_information(struct ata_queued_cmd *qc)
222220
{
223221
u64 information;
224222

225-
information = ata_tf_read_block(tf, dev);
223+
if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) {
224+
ata_dev_dbg(qc->dev,
225+
"missing result TF: can't set INFORMATION sense field\n");
226+
return;
227+
}
228+
229+
information = ata_tf_read_block(&qc->result_tf, qc->dev);
226230
if (information == U64_MAX)
227231
return;
228232

229-
scsi_set_sense_information(cmd->sense_buffer,
233+
scsi_set_sense_information(qc->scsicmd->sense_buffer,
230234
SCSI_SENSE_BUFFERSIZE, information);
231235
}
232236

@@ -971,8 +975,7 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
971975
* ata_gen_ata_sense - generate a SCSI fixed sense block
972976
* @qc: Command that we are erroring out
973977
*
974-
* Generate sense block for a failed ATA command @qc. Descriptor
975-
* format is used to accommodate LBA48 block address.
978+
* Generate sense block for a failed ATA command @qc.
976979
*
977980
* LOCKING:
978981
* None.
@@ -982,8 +985,6 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc)
982985
struct ata_device *dev = qc->dev;
983986
struct scsi_cmnd *cmd = qc->scsicmd;
984987
struct ata_taskfile *tf = &qc->result_tf;
985-
unsigned char *sb = cmd->sense_buffer;
986-
u64 block;
987988
u8 sense_key, asc, ascq;
988989

989990
if (ata_dev_disabled(dev)) {
@@ -1014,12 +1015,6 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc)
10141015
ata_scsi_set_sense(dev, cmd, ABORTED_COMMAND, 0, 0);
10151016
return;
10161017
}
1017-
1018-
block = ata_tf_read_block(&qc->result_tf, dev);
1019-
if (block == U64_MAX)
1020-
return;
1021-
1022-
scsi_set_sense_information(sb, SCSI_SENSE_BUFFERSIZE, block);
10231018
}
10241019

10251020
void ata_scsi_sdev_config(struct scsi_device *sdev)
@@ -1679,8 +1674,10 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
16791674
ata_scsi_set_passthru_sense_fields(qc);
16801675
if (is_ck_cond_request)
16811676
set_status_byte(qc->scsicmd, SAM_STAT_CHECK_CONDITION);
1682-
} else if (is_error && !have_sense) {
1683-
ata_gen_ata_sense(qc);
1677+
} else if (is_error) {
1678+
if (!have_sense)
1679+
ata_gen_ata_sense(qc);
1680+
ata_scsi_set_sense_information(qc);
16841681
}
16851682

16861683
ata_qc_done(qc);

drivers/ata/libata.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ extern int ata_scsi_offline_dev(struct ata_device *dev);
141141
extern bool ata_scsi_sense_is_valid(u8 sk, u8 asc, u8 ascq);
142142
extern void ata_scsi_set_sense(struct ata_device *dev,
143143
struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq);
144-
extern void ata_scsi_set_sense_information(struct ata_device *dev,
145-
struct scsi_cmnd *cmd,
146-
const struct ata_taskfile *tf);
147144
extern void ata_scsi_media_change_notify(struct ata_device *dev);
148145
extern void ata_scsi_hotplug(struct work_struct *work);
149146
extern void ata_scsi_dev_rescan(struct work_struct *work);

0 commit comments

Comments
 (0)