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