blob: 4416b1026189c182bb75fbc5f677f587007522a7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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 Bottomley86e33a22006-08-30 09:45:51 -04007#include <scsi/scsi_host.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#define SCSI_NO_TAG (-1) /* identify no tag in use */
10
11
David Howells93614012006-09-30 20:45:40 +020012#ifdef CONFIG_BLOCK
David C Somayajuluf583f492006-10-04 08:27:25 +020013/**
14 * scsi_host_find_tag - find the tagged command by host
15 * @shost: pointer to scsi_host
Christoph Hellwig64d513ac2015-10-08 09:28:04 +010016 * @tag: tag
David C Somayajuluf583f492006-10-04 08:27:25 +020017 *
Christoph Hellwig64d513ac2015-10-08 09:28:04 +010018 * Note: for devices using multiple hardware queues tag must have been
19 * generated by blk_mq_unique_tag().
David C Somayajuluf583f492006-10-04 08:27:25 +020020 **/
21static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost,
Christoph Hellwig64d513ac2015-10-08 09:28:04 +010022 int tag)
David C Somayajuluf583f492006-10-04 08:27:25 +020023{
Christoph Hellwig64d513ac2015-10-08 09:28:04 +010024 struct request *req = NULL;
David C Somayajuluf583f492006-10-04 08:27:25 +020025
Christoph Hellwig64d513ac2015-10-08 09:28:04 +010026 if (tag == SCSI_NO_TAG)
27 return NULL;
28
29 if (shost_use_blk_mq(shost)) {
30 u16 hwq = blk_mq_unique_tag_to_hwq(tag);
31
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));
35 }
36 } else {
David C Somayajuluf583f492006-10-04 08:27:25 +020037 req = blk_map_queue_find_tag(shost->bqt, tag);
David C Somayajuluf583f492006-10-04 08:27:25 +020038 }
Christoph Hellwig64d513ac2015-10-08 09:28:04 +010039
40 if (!req)
41 return NULL;
42 return req->special;
David C Somayajuluf583f492006-10-04 08:27:25 +020043}
44
David Howells93614012006-09-30 20:45:40 +020045#endif /* CONFIG_BLOCK */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#endif /* _SCSI_SCSI_TCQ_H */