Skip to content

Commit b1ba03c

Browse files
damien-lemoalmartinkpetersen
authored andcommitted
scsi: core: Remember if a device is an ATA device
scsi_add_lun() tests the device vendor string of SCSI devices to detect if a SCSI device is in fact an ATA device, in order to correctly handle SATL power management. The function scsi_cdl_enable() also requires knowing if a SCSI device is an ATA device to control the state of the device CDL feature but this function does that by testing for the presence of the VPD page 89h (ATA INFORMATION page). sd_read_write_same() also has a similar test. Simplify these different methods by adding the is_ata field to struct scsi_device to remember that a SCSI device is in fact an ATA one based on the device vendor name test. This field can also allow low level SCSI host adapter drivers to take special actions for ATA devices (e.g. to better handle ATA NCQ errors). With this, simplify scsi_cdl_enable() and sd_read_write_same(). Signed-off-by: Damien Le Moal <dlemoal@kernel.org> Link: https://lore.kernel.org/r/20250611093421.2901633-1-dlemoal@kernel.org Reviewed-by: Igor Pylypiv <ipylypiv@google.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 0ec996e commit b1ba03c

4 files changed

Lines changed: 12 additions & 16 deletions

File tree

drivers/scsi/scsi.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -708,20 +708,15 @@ void scsi_cdl_check(struct scsi_device *sdev)
708708
int scsi_cdl_enable(struct scsi_device *sdev, bool enable)
709709
{
710710
char buf[64];
711-
bool is_ata;
712711
int ret;
713712

714713
if (!sdev->cdl_supported)
715714
return -EOPNOTSUPP;
716715

717-
rcu_read_lock();
718-
is_ata = rcu_dereference(sdev->vpd_pg89);
719-
rcu_read_unlock();
720-
721716
/*
722717
* For ATA devices, CDL needs to be enabled with a SET FEATURES command.
723718
*/
724-
if (is_ata) {
719+
if (sdev->is_ata) {
725720
struct scsi_mode_data data;
726721
struct scsi_sense_hdr sshdr;
727722
char *buf_data;

drivers/scsi/scsi_scan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,8 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
909909
sdev->model = (char *) (sdev->inquiry + 16);
910910
sdev->rev = (char *) (sdev->inquiry + 32);
911911

912-
if (strncmp(sdev->vendor, "ATA ", 8) == 0) {
912+
sdev->is_ata = strncmp(sdev->vendor, "ATA ", 8) == 0;
913+
if (sdev->is_ata) {
913914
/*
914915
* sata emulation layer device. This is a hack to work around
915916
* the SATL power management specifications which state that

drivers/scsi/sd.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3459,19 +3459,14 @@ static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer)
34593459
}
34603460

34613461
if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, INQUIRY, 0) < 0) {
3462-
struct scsi_vpd *vpd;
3463-
34643462
sdev->no_report_opcodes = 1;
34653463

3466-
/* Disable WRITE SAME if REPORT SUPPORTED OPERATION
3467-
* CODES is unsupported and the device has an ATA
3468-
* Information VPD page (SAT).
3464+
/*
3465+
* Disable WRITE SAME if REPORT SUPPORTED OPERATION CODES is
3466+
* unsupported and this is an ATA device.
34693467
*/
3470-
rcu_read_lock();
3471-
vpd = rcu_dereference(sdev->vpd_pg89);
3472-
if (vpd)
3468+
if (sdev->is_ata)
34733469
sdev->no_write_same = 1;
3474-
rcu_read_unlock();
34753470
}
34763471

34773472
if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME_16, 0) == 1)

include/scsi/scsi_device.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ struct scsi_device {
184184
*/
185185
unsigned force_runtime_start_on_system_start:1;
186186

187+
/*
188+
* Set if the device is an ATA device.
189+
*/
190+
unsigned is_ata:1;
191+
187192
unsigned removable:1;
188193
unsigned changed:1; /* Data invalid due to media change */
189194
unsigned busy:1; /* Used to prevent races */

0 commit comments

Comments
 (0)