Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
James Bottomley | 86e33a2 | 2006-08-30 09:45:51 -0400 | [diff] [blame] | 8 | #include <scsi/scsi_host.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #define SCSI_NO_TAG (-1) /* identify no tag in use */ |
| 11 | |
| 12 | |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 13 | #ifdef CONFIG_BLOCK |
David C Somayajulu | f583f49 | 2006-10-04 08:27:25 +0200 | [diff] [blame] | 14 | /** |
| 15 | * scsi_host_find_tag - find the tagged command by host |
| 16 | * @shost: pointer to scsi_host |
Christoph Hellwig | 64d513a | 2015-10-08 09:28:04 +0100 | [diff] [blame] | 17 | * @tag: tag |
David C Somayajulu | f583f49 | 2006-10-04 08:27:25 +0200 | [diff] [blame] | 18 | * |
Christoph Hellwig | 64d513a | 2015-10-08 09:28:04 +0100 | [diff] [blame] | 19 | * Note: for devices using multiple hardware queues tag must have been |
| 20 | * generated by blk_mq_unique_tag(). |
David C Somayajulu | f583f49 | 2006-10-04 08:27:25 +0200 | [diff] [blame] | 21 | **/ |
| 22 | static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost, |
Christoph Hellwig | 64d513a | 2015-10-08 09:28:04 +0100 | [diff] [blame] | 23 | int tag) |
David C Somayajulu | f583f49 | 2006-10-04 08:27:25 +0200 | [diff] [blame] | 24 | { |
Christoph Hellwig | 64d513a | 2015-10-08 09:28:04 +0100 | [diff] [blame] | 25 | struct request *req = NULL; |
Jens Axboe | f664a3c | 2018-11-01 16:36:27 -0600 | [diff] [blame] | 26 | u16 hwq; |
David C Somayajulu | f583f49 | 2006-10-04 08:27:25 +0200 | [diff] [blame] | 27 | |
Christoph Hellwig | 64d513a | 2015-10-08 09:28:04 +0100 | [diff] [blame] | 28 | if (tag == SCSI_NO_TAG) |
| 29 | return NULL; |
| 30 | |
Jens Axboe | f664a3c | 2018-11-01 16:36:27 -0600 | [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)); |
David C Somayajulu | f583f49 | 2006-10-04 08:27:25 +0200 | [diff] [blame] | 35 | } |
Christoph Hellwig | 64d513a | 2015-10-08 09:28:04 +0100 | [diff] [blame] | 36 | |
Hannes Reinecke | e73a5e8 | 2020-06-22 08:30:22 +0200 | [diff] [blame] | 37 | if (!req || !blk_mq_request_started(req)) |
Christoph Hellwig | 64d513a | 2015-10-08 09:28:04 +0100 | [diff] [blame] | 38 | return NULL; |
Bart Van Assche | bed2213 | 2017-08-25 13:46:32 -0700 | [diff] [blame] | 39 | return blk_mq_rq_to_pdu(req); |
David C Somayajulu | f583f49 | 2006-10-04 08:27:25 +0200 | [diff] [blame] | 40 | } |
| 41 | |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 42 | #endif /* CONFIG_BLOCK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #endif /* _SCSI_SCSI_TCQ_H */ |