From c9476f104c6cdf263b883b3aa970376b9dc347cc Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Mon, 27 Feb 2023 11:57:52 +0300 Subject: [PATCH] scst: Port to Linux kernel v6.3 Support for the following scsi core changes in the Linux kernel v6.3: - d0949565811f ("scsi: core: Add struct for args to execution functions") --- scst/include/backport.h | 7 ++++ scst/include/scst.h | 64 +++++++++++++++++++++-------- scst/src/dev_handlers/scst_cdrom.c | 6 +-- scst/src/dev_handlers/scst_disk.c | 12 +++--- scst/src/dev_handlers/scst_modisk.c | 6 +-- scst/src/scst_lib.c | 10 ++--- 6 files changed, 71 insertions(+), 34 deletions(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index 1e7e1cc63..c02cf54c1 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -177,6 +177,13 @@ enum { }; #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 0, 0) +/* + * See also commit 342a72a33407 ("block: Introduce the type blk_opf_t") # v6.0 + */ +typedef unsigned int blk_opf_t; +#endif + /* */ static inline unsigned int scst_blk_rq_cpu(struct request *rq) diff --git a/scst/include/scst.h b/scst/include/scst.h index f83dc4be8..1e754cbca 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -5551,34 +5551,64 @@ ssize_t scst_readv(struct file *file, const struct kvec *vec, ssize_t scst_writev(struct file *file, const struct kvec *vec, unsigned long vlen, loff_t *pos); void scst_write_same(struct scst_cmd *cmd, struct scst_data_descriptor *where); + /** - * scsi_execute - insert a SCSI request and wait for the result - * @sdev: scsi device + * __scst_scsi_execute_cmd - insert request and wait for the result + * @sdev: scsi_device * @cmd: scsi command - * @data_direction: data direction + * @data_direction: data direction - DMA_TO_DEVICE or DMA_FROM_DEVICE * @buffer: data buffer - * @bufflen: length of buffer - DMA_TO_DEVICE, DMA_FROM_DEVICE or DMA_NONE - * @sense: optional sense buffer - * @timeout: request timeout in seconds + * @bufflen: len of buffer + * @sensebuf: sense buffer + * @sense_len: len of sense buffer + * @timeout: request timeout in HZ * @retries: number of times to retry request - * @flags: flags for ->cmd_flags, e.g. REQ_FAILFAST_DEV + * @opf: block layer request cmd_flags * * Returns the scsi_cmnd result field if a command was executed, or a negative * Linux error code if we didn't get that far. */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) -#define scst_scsi_execute(sdev, cmd, data_direction, buffer, bufflen, sense, \ - timeout, retries, flags) \ - scsi_execute(sdev, cmd, data_direction, buffer, bufflen, sense, \ - NULL /* sshdr */, timeout, retries, flags, \ - 0 /* rq_flags */, NULL /* resid */) +static inline int +__scst_scsi_execute_cmd(struct scsi_device *sdev, const unsigned char *cmd, + int data_direction, void *buffer, unsigned int bufflen, + unsigned char *sense, unsigned int sense_len, + int timeout, int retries, blk_opf_t opf) +{ +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) + if (WARN_ON_ONCE(sense && sense_len != SCSI_SENSE_BUFFERSIZE)) + return -EINVAL; + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) + return scsi_execute(sdev, cmd, data_direction, buffer, bufflen, sense, + timeout, retries, opf, /*resid=*/NULL); + +#elif LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0) && \ + (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 8) + return scsi_execute(sdev, cmd, data_direction, buffer, bufflen, sense, + /*sshdr=*/NULL, timeout, retries, opf, + /*rq_flags=*/0, /*resid=*/NULL); #else -#define scst_scsi_execute(sdev, cmd, data_direction, buffer, bufflen, sense, \ - timeout, retries, flags) \ - scsi_execute(sdev, cmd, data_direction, buffer, bufflen, sense, \ - timeout, retries, flags, NULL /* resid */) + return __scsi_execute(sdev, cmd, data_direction, buffer, bufflen, sense, + /*sshdr=*/NULL, timeout, retries, opf, + /*rq_flags=*/0, /*resid=*/NULL); #endif +#else + opf |= data_direction == DMA_TO_DEVICE ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN; + + return scsi_execute_cmd(sdev, cmd, opf, buffer, bufflen, timeout, + retries, &(struct scsi_exec_args) { + .sense = sense, + .sense_len = sense_len, + }); +#endif +} + +#define scst_scsi_execute_cmd(sdev, cmd, data_direction, buffer, bufflen, sense, \ + timeout, retries, opf) \ + __scst_scsi_execute_cmd(sdev, cmd, data_direction, buffer, bufflen, sense, \ + sizeof(sense), timeout, retries, opf) + __be64 scst_pack_lun(const uint64_t lun, enum scst_lun_addr_method addr_method); uint64_t scst_unpack_lun(const uint8_t *lun, int len); diff --git a/scst/src/dev_handlers/scst_cdrom.c b/scst/src/dev_handlers/scst_cdrom.c index 04c683c3d..d35be0677 100644 --- a/scst/src/dev_handlers/scst_cdrom.c +++ b/scst/src/dev_handlers/scst_cdrom.c @@ -94,9 +94,9 @@ static int cdrom_attach(struct scst_device *dev) memset(sense_buffer, 0, sizeof(sense_buffer)); TRACE_DBG("%s", "Doing READ_CAPACITY"); - rc = scst_scsi_execute(dev->scsi_dev, cmd, DMA_FROM_DEVICE, - buffer, buffer_size, sense_buffer, - SCST_GENERIC_CDROM_REG_TIMEOUT, 3, 0); + rc = scst_scsi_execute_cmd(dev->scsi_dev, cmd, DMA_FROM_DEVICE, + buffer, buffer_size, sense_buffer, + SCST_GENERIC_CDROM_REG_TIMEOUT, 3, 0); TRACE_DBG("READ_CAPACITY done: %x", rc); diff --git a/scst/src/dev_handlers/scst_disk.c b/scst/src/dev_handlers/scst_disk.c index 9150dd5e2..341a05a12 100644 --- a/scst/src/dev_handlers/scst_disk.c +++ b/scst/src/dev_handlers/scst_disk.c @@ -79,9 +79,9 @@ static int disk_attach(struct scst_device *dev) memset(sense_buffer, 0, sizeof(sense_buffer)); TRACE_DBG("%s", "Doing READ_CAPACITY"); - rc = scst_scsi_execute(dev->scsi_dev, cmd, DMA_FROM_DEVICE, - buffer, buffer_size, sense_buffer, - SCST_GENERIC_DISK_REG_TIMEOUT, 3, 0); + rc = scst_scsi_execute_cmd(dev->scsi_dev, cmd, DMA_FROM_DEVICE, + buffer, buffer_size, sense_buffer, + SCST_GENERIC_DISK_REG_TIMEOUT, 3, 0); TRACE_DBG("READ_CAPACITY done: %x", rc); @@ -135,9 +135,9 @@ static int disk_attach(struct scst_device *dev) memset(sense_buffer, 0, sizeof(sense_buffer)); TRACE_DBG("%s", "Doing INQUIRY (Unit Serial Number VPD)"); - rc = scst_scsi_execute(dev->scsi_dev, cmd, DMA_FROM_DEVICE, - buffer, buffer_size, sense_buffer, - SCST_GENERIC_DISK_REG_TIMEOUT, 3, 0); + rc = scst_scsi_execute_cmd(dev->scsi_dev, cmd, DMA_FROM_DEVICE, + buffer, buffer_size, sense_buffer, + SCST_GENERIC_DISK_REG_TIMEOUT, 3, 0); TRACE_DBG("INQUIRY (Unit Serial Number VPD) done: %x", rc); diff --git a/scst/src/dev_handlers/scst_modisk.c b/scst/src/dev_handlers/scst_modisk.c index 65699963b..ace433646 100644 --- a/scst/src/dev_handlers/scst_modisk.c +++ b/scst/src/dev_handlers/scst_modisk.c @@ -175,9 +175,9 @@ static int modisk_attach(struct scst_device *dev) memset(sense_buffer, 0, sizeof(sense_buffer)); TRACE_DBG("%s", "Doing READ_CAPACITY"); - rc = scst_scsi_execute(dev->scsi_dev, cmd, DMA_FROM_DEVICE, - buffer, buffer_size, sense_buffer, - SCST_GENERIC_MODISK_REG_TIMEOUT, 3, 0); + rc = scst_scsi_execute_cmd(dev->scsi_dev, cmd, DMA_FROM_DEVICE, + buffer, buffer_size, sense_buffer, + SCST_GENERIC_MODISK_REG_TIMEOUT, 3, 0); TRACE_DBG("READ_CAPACITY done: %x", rc); diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 868406000..bc3a83af3 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -7047,8 +7047,8 @@ static void scst_send_release(struct scst_device *dev) TRACE(TRACE_DEBUG | TRACE_SCSI, "%s", "Sending RELEASE req to " "SCSI mid-level"); - rc = scst_scsi_execute(scsi_dev, cdb, SCST_DATA_NONE, NULL, 0, - sense, 15, 0, 0); + rc = scst_scsi_execute_cmd(scsi_dev, cdb, DMA_FROM_DEVICE, + NULL, 0, sense, 15, 0, 0); TRACE_DBG("RELEASE done: %x", rc); if (scsi_status_is_good(rc)) @@ -13632,9 +13632,9 @@ int scst_obtain_device_parameters(struct scst_device *dev, memset(sense_buffer, 0, sizeof(sense_buffer)); TRACE(TRACE_SCSI, "%s", "Doing internal MODE_SENSE"); - rc = scst_scsi_execute(dev->scsi_dev, cmd, SCST_DATA_READ, - buffer, sizeof(buffer), sense_buffer, - 15, 0, 0); + rc = scst_scsi_execute_cmd(dev->scsi_dev, cmd, DMA_FROM_DEVICE, + buffer, sizeof(buffer), + sense_buffer, 15, 0, 0); TRACE_DBG("MODE_SENSE done: %x", rc);