Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: core: Support Service Action in scsi_report_opcode()

The REPORT_SUPPORTED_OPERATION_CODES command allows checking for support of
commands that have the same opcode but different service actions, such as
READ 32 and WRITE 32. However, the current implementation of
scsi_report_opcode() only allows checking an operation code without a
service action differentiation.

Add the "sa" argument to scsi_report_opcode() to allow passing a service
action. If a non-zero service action is specified, the reporting options
field value is set to 3 to have the service action field taken into account
by the device. If no service action field is specified (zero), the
reporting options field is set to 1 as before.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Link: https://lore.kernel.org/r/20230511011356.227789-8-nks@flawful.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Damien Le Moal and committed by
Martin K. Petersen
152e52fb a6cdc35f

+26 -15
+18 -8
drivers/scsi/scsi.c
··· 504 504 } 505 505 506 506 /** 507 - * scsi_report_opcode - Find out if a given command opcode is supported 507 + * scsi_report_opcode - Find out if a given command is supported 508 508 * @sdev: scsi device to query 509 509 * @buffer: scratch buffer (must be at least 20 bytes long) 510 510 * @len: length of buffer 511 - * @opcode: opcode for command to look up 511 + * @opcode: opcode for the command to look up 512 + * @sa: service action for the command to look up 512 513 * 513 - * Uses the REPORT SUPPORTED OPERATION CODES to look up the given 514 - * opcode. Returns -EINVAL if RSOC fails, 0 if the command opcode is 515 - * unsupported and 1 if the device claims to support the command. 514 + * Uses the REPORT SUPPORTED OPERATION CODES to check support for the 515 + * command identified with @opcode and @sa. If the command does not 516 + * have a service action, @sa must be 0. Returns -EINVAL if RSOC fails, 517 + * 0 if the command is not supported and 1 if the device claims to 518 + * support the command. 516 519 */ 517 520 int scsi_report_opcode(struct scsi_device *sdev, unsigned char *buffer, 518 - unsigned int len, unsigned char opcode) 521 + unsigned int len, unsigned char opcode, 522 + unsigned short sa) 519 523 { 520 524 unsigned char cmd[16]; 521 525 struct scsi_sense_hdr sshdr; ··· 543 539 memset(cmd, 0, 16); 544 540 cmd[0] = MAINTENANCE_IN; 545 541 cmd[1] = MI_REPORT_SUPPORTED_OPERATION_CODES; 546 - cmd[2] = 1; /* One command format */ 547 - cmd[3] = opcode; 542 + if (!sa) { 543 + cmd[2] = 1; /* One command format */ 544 + cmd[3] = opcode; 545 + } else { 546 + cmd[2] = 3; /* One command format with service action */ 547 + cmd[3] = opcode; 548 + put_unaligned_be16(sa, &cmd[4]); 549 + } 548 550 put_unaligned_be32(request_len, &cmd[6]); 549 551 memset(buffer, 0, len); 550 552
+5 -5
drivers/scsi/sd.c
··· 3056 3056 return; 3057 3057 } 3058 3058 3059 - if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, INQUIRY) < 0) { 3059 + if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, INQUIRY, 0) < 0) { 3060 3060 struct scsi_vpd *vpd; 3061 3061 3062 3062 sdev->no_report_opcodes = 1; ··· 3072 3072 rcu_read_unlock(); 3073 3073 } 3074 3074 3075 - if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME_16) == 1) 3075 + if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME_16, 0) == 1) 3076 3076 sdkp->ws16 = 1; 3077 3077 3078 - if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME) == 1) 3078 + if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME, 0) == 1) 3079 3079 sdkp->ws10 = 1; 3080 3080 } 3081 3081 ··· 3087 3087 return; 3088 3088 3089 3089 if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, 3090 - SECURITY_PROTOCOL_IN) == 1 && 3090 + SECURITY_PROTOCOL_IN, 0) == 1 && 3091 3091 scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, 3092 - SECURITY_PROTOCOL_OUT) == 1) 3092 + SECURITY_PROTOCOL_OUT, 0) == 1) 3093 3093 sdkp->security = 1; 3094 3094 } 3095 3095
+3 -2
include/scsi/scsi_device.h
··· 433 433 int retries, struct scsi_sense_hdr *sshdr); 434 434 extern int scsi_get_vpd_page(struct scsi_device *, u8 page, unsigned char *buf, 435 435 int buf_len); 436 - extern int scsi_report_opcode(struct scsi_device *sdev, unsigned char *buffer, 437 - unsigned int len, unsigned char opcode); 436 + int scsi_report_opcode(struct scsi_device *sdev, unsigned char *buffer, 437 + unsigned int len, unsigned char opcode, 438 + unsigned short sa); 438 439 extern int scsi_device_set_state(struct scsi_device *sdev, 439 440 enum scsi_device_state state); 440 441 extern struct scsi_event *sdev_evt_alloc(enum scsi_device_event evt_type,