Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _SCSI_SCSI_TCQ_H |
| 2 | #define _SCSI_SCSI_TCQ_H |
| 3 | |
| 4 | #include <linux/blkdev.h> |
| 5 | #include <scsi/scsi_cmnd.h> |
| 6 | #include <scsi/scsi_device.h> |
James Bottomley | 86e33a2 | 2006-08-30 09:45:51 -0400 | [diff] [blame] | 7 | #include <scsi/scsi_host.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #define SCSI_NO_TAG (-1) /* identify no tag in use */ |
| 10 | |
| 11 | |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 12 | #ifdef CONFIG_BLOCK |
Christoph Hellwig | d285203 | 2014-01-17 12:06:53 +0100 | [diff] [blame] | 13 | static inline struct scsi_cmnd *scsi_mq_find_tag(struct Scsi_Host *shost, |
Bart Van Assche | 1ee8e88 | 2014-10-30 14:46:00 +0100 | [diff] [blame] | 14 | int unique_tag) |
Christoph Hellwig | d285203 | 2014-01-17 12:06:53 +0100 | [diff] [blame] | 15 | { |
Bart Van Assche | 1ee8e88 | 2014-10-30 14:46:00 +0100 | [diff] [blame] | 16 | u16 hwq = blk_mq_unique_tag_to_hwq(unique_tag); |
| 17 | struct request *req = NULL; |
Christoph Hellwig | d285203 | 2014-01-17 12:06:53 +0100 | [diff] [blame] | 18 | |
Bart Van Assche | 1ee8e88 | 2014-10-30 14:46:00 +0100 | [diff] [blame] | 19 | if (hwq < shost->tag_set.nr_hw_queues) |
| 20 | req = blk_mq_tag_to_rq(shost->tag_set.tags[hwq], |
| 21 | blk_mq_unique_tag_to_tag(unique_tag)); |
Christoph Hellwig | d285203 | 2014-01-17 12:06:53 +0100 | [diff] [blame] | 22 | return req ? (struct scsi_cmnd *)req->special : NULL; |
| 23 | } |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | /** |
| 26 | * scsi_find_tag - find a tagged command by device |
| 27 | * @SDpnt: pointer to the ScSI device |
Bart Van Assche | 1ee8e88 | 2014-10-30 14:46:00 +0100 | [diff] [blame] | 28 | * @tag: tag generated by blk_mq_unique_tag() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | * |
| 30 | * Notes: |
| 31 | * Only works with tags allocated by the generic blk layer. |
| 32 | **/ |
| 33 | static inline struct scsi_cmnd *scsi_find_tag(struct scsi_device *sdev, int tag) |
| 34 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | struct request *req; |
| 36 | |
| 37 | if (tag != SCSI_NO_TAG) { |
Christoph Hellwig | d285203 | 2014-01-17 12:06:53 +0100 | [diff] [blame] | 38 | if (shost_use_blk_mq(sdev->host)) |
Bart Van Assche | 1ee8e88 | 2014-10-30 14:46:00 +0100 | [diff] [blame] | 39 | return scsi_mq_find_tag(sdev->host, tag); |
Christoph Hellwig | d285203 | 2014-01-17 12:06:53 +0100 | [diff] [blame] | 40 | |
Bart Van Assche | 1ee8e88 | 2014-10-30 14:46:00 +0100 | [diff] [blame] | 41 | req = blk_queue_find_tag(sdev->request_queue, tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | return req ? (struct scsi_cmnd *)req->special : NULL; |
| 43 | } |
| 44 | |
| 45 | /* single command, look in space */ |
| 46 | return sdev->current_cmnd; |
| 47 | } |
| 48 | |
Christoph Hellwig | d285203 | 2014-01-17 12:06:53 +0100 | [diff] [blame] | 49 | |
James Bottomley | 86e33a2 | 2006-08-30 09:45:51 -0400 | [diff] [blame] | 50 | /** |
| 51 | * scsi_init_shared_tag_map - create a shared tag map |
| 52 | * @shost: the host to share the tag map among all devices |
| 53 | * @depth: the total depth of the map |
| 54 | */ |
James Bottomley | deb81d8 | 2006-09-01 09:28:48 -0400 | [diff] [blame] | 55 | static inline int scsi_init_shared_tag_map(struct Scsi_Host *shost, int depth) |
James Bottomley | 86e33a2 | 2006-08-30 09:45:51 -0400 | [diff] [blame] | 56 | { |
Jens Axboe | 3070f69 | 2008-10-27 19:20:59 +0100 | [diff] [blame] | 57 | /* |
Christoph Hellwig | d285203 | 2014-01-17 12:06:53 +0100 | [diff] [blame] | 58 | * We always have a shared tag map around when using blk-mq. |
| 59 | */ |
| 60 | if (shost_use_blk_mq(shost)) |
| 61 | return 0; |
| 62 | |
| 63 | /* |
Jens Axboe | 3070f69 | 2008-10-27 19:20:59 +0100 | [diff] [blame] | 64 | * If the shared tag map isn't already initialized, do it now. |
| 65 | * This saves callers from having to check ->bqt when setting up |
| 66 | * devices on the shared host (for libata) |
| 67 | */ |
| 68 | if (!shost->bqt) { |
| 69 | shost->bqt = blk_init_tags(depth); |
| 70 | if (!shost->bqt) |
| 71 | return -ENOMEM; |
| 72 | } |
| 73 | |
| 74 | return 0; |
James Bottomley | 86e33a2 | 2006-08-30 09:45:51 -0400 | [diff] [blame] | 75 | } |
| 76 | |
David C Somayajulu | f583f49 | 2006-10-04 08:27:25 +0200 | [diff] [blame] | 77 | /** |
| 78 | * scsi_host_find_tag - find the tagged command by host |
| 79 | * @shost: pointer to scsi_host |
Bart Van Assche | 1ee8e88 | 2014-10-30 14:46:00 +0100 | [diff] [blame] | 80 | * @tag: tag generated by blk_mq_unique_tag() |
David C Somayajulu | f583f49 | 2006-10-04 08:27:25 +0200 | [diff] [blame] | 81 | * |
| 82 | * Notes: |
| 83 | * Only works with tags allocated by the generic blk layer. |
| 84 | **/ |
| 85 | static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost, |
| 86 | int tag) |
| 87 | { |
| 88 | struct request *req; |
| 89 | |
| 90 | if (tag != SCSI_NO_TAG) { |
Christoph Hellwig | d285203 | 2014-01-17 12:06:53 +0100 | [diff] [blame] | 91 | if (shost_use_blk_mq(shost)) |
Bart Van Assche | 1ee8e88 | 2014-10-30 14:46:00 +0100 | [diff] [blame] | 92 | return scsi_mq_find_tag(shost, tag); |
David C Somayajulu | f583f49 | 2006-10-04 08:27:25 +0200 | [diff] [blame] | 93 | req = blk_map_queue_find_tag(shost->bqt, tag); |
| 94 | return req ? (struct scsi_cmnd *)req->special : NULL; |
| 95 | } |
| 96 | return NULL; |
| 97 | } |
| 98 | |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 99 | #endif /* CONFIG_BLOCK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | #endif /* _SCSI_SCSI_TCQ_H */ |