^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef _SCSI_SCSI_TCQ_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _SCSI_SCSI_TCQ_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define SCSI_NO_TAG (-1) /* identify no tag in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #ifdef CONFIG_BLOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * scsi_host_find_tag - find the tagged command by host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * @shost: pointer to scsi_host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * @tag: tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Note: for devices using multiple hardware queues tag must have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * generated by blk_mq_unique_tag().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) int tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct request *req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) u16 hwq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (tag == SCSI_NO_TAG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) hwq = blk_mq_unique_tag_to_hwq(tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if (hwq < shost->tag_set.nr_hw_queues) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) req = blk_mq_tag_to_rq(shost->tag_set.tags[hwq],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) blk_mq_unique_tag_to_tag(tag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (!req || !blk_mq_request_started(req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return blk_mq_rq_to_pdu(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #endif /* CONFIG_BLOCK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #endif /* _SCSI_SCSI_TCQ_H */