Skip to content

Commit a6ac0af

Browse files
committed
ata: libata-scsi: refactor ata_scsiop_maint_in()
ata_scsiop_maint_in() is currently quite confusing to read, because it currently only implements support for the service action REPORT SUPPORTED OPERATION CODES. Thus, when this function is checking for "invalid command format", it is not very clear if it is an invalid command format for the MAINTENANCE IN command itself, or an invalid command format for the (currently one and only) service action/subcommand implemented for this command. Move the service action to a separate function, so it is more clear that the "invalid command format" check is actually specific for the REPORT SUPPORTED OPERATION CODES service action. This also makes it easier and less confusing to add support for additional service actions in the future. Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Signed-off-by: Niklas Cassel <cassel@kernel.org>
1 parent d78c5bb commit a6ac0af

1 file changed

Lines changed: 29 additions & 18 deletions

File tree

drivers/ata/libata-scsi.c

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3573,28 +3573,13 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc)
35733573
return 1;
35743574
}
35753575

3576-
/**
3577-
* ata_scsiop_maint_in - Simulate a subset of MAINTENANCE_IN
3578-
* @dev: Target device.
3579-
* @cmd: SCSI command of interest.
3580-
* @rbuf: Response buffer, to which simulated SCSI cmd output is sent.
3581-
*
3582-
* Yields a subset to satisfy scsi_report_opcode()
3583-
*
3584-
* LOCKING:
3585-
* spin_lock_irqsave(host lock)
3586-
*/
3587-
static unsigned int ata_scsiop_maint_in(struct ata_device *dev,
3588-
struct scsi_cmnd *cmd, u8 *rbuf)
3576+
static unsigned int ata_scsi_report_supported_opcodes(struct ata_device *dev,
3577+
struct scsi_cmnd *cmd,
3578+
u8 *rbuf)
35893579
{
35903580
u8 *cdb = cmd->cmnd;
35913581
u8 supported = 0, cdlp = 0, rwcdlp = 0;
35923582

3593-
if ((cdb[1] & 0x1f) != MI_REPORT_SUPPORTED_OPERATION_CODES) {
3594-
ata_scsi_set_invalid_field(dev, cmd, 1, 0xff);
3595-
return 0;
3596-
}
3597-
35983583
if (cdb[2] != 1 && cdb[2] != 3) {
35993584
ata_dev_warn(dev, "invalid command format %d\n", cdb[2]);
36003585
ata_scsi_set_invalid_field(dev, cmd, 2, 0xff);
@@ -3674,6 +3659,32 @@ static unsigned int ata_scsiop_maint_in(struct ata_device *dev,
36743659
return 4;
36753660
}
36763661

3662+
/**
3663+
* ata_scsiop_maint_in - Simulate a subset of MAINTENANCE_IN
3664+
* @dev: Target device.
3665+
* @cmd: SCSI command of interest.
3666+
* @rbuf: Response buffer, to which simulated SCSI cmd output is sent.
3667+
*
3668+
* Yields a subset to satisfy scsi_report_opcode()
3669+
*
3670+
* LOCKING:
3671+
* spin_lock_irqsave(host lock)
3672+
*/
3673+
static unsigned int ata_scsiop_maint_in(struct ata_device *dev,
3674+
struct scsi_cmnd *cmd, u8 *rbuf)
3675+
{
3676+
u8 *cdb = cmd->cmnd;
3677+
u8 service_action = cdb[1] & 0x1f;
3678+
3679+
switch (service_action) {
3680+
case MI_REPORT_SUPPORTED_OPERATION_CODES:
3681+
return ata_scsi_report_supported_opcodes(dev, cmd, rbuf);
3682+
default:
3683+
ata_scsi_set_invalid_field(dev, cmd, 1, 0xff);
3684+
return 0;
3685+
}
3686+
}
3687+
36773688
/**
36783689
* ata_scsi_report_zones_complete - convert ATA output
36793690
* @qc: command structure returning the data

0 commit comments

Comments
 (0)