blob: e192a0caa8509294de01b851606ebaa3de3145a6 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#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 Bottomley86e33a22006-08-30 09:45:51 -04008#include <scsi/scsi_host.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#define SCSI_NO_TAG (-1) /* identify no tag in use */
11
12
David Howells93614012006-09-30 20:45:40 +020013#ifdef CONFIG_BLOCK
David C Somayajuluf583f492006-10-04 08:27:25 +020014/**
15 * scsi_host_find_tag - find the tagged command by host
16 * @shost: pointer to scsi_host
Christoph Hellwig64d513ac2015-10-08 09:28:04 +010017 * @tag: tag
David C Somayajuluf583f492006-10-04 08:27:25 +020018 *
Christoph Hellwig64d513ac2015-10-08 09:28:04 +010019 * Note: for devices using multiple hardware queues tag must have been
20 * generated by blk_mq_unique_tag().
David C Somayajuluf583f492006-10-04 08:27:25 +020021 **/
22static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost,
Christoph Hellwig64d513ac2015-10-08 09:28:04 +010023 int tag)
David C Somayajuluf583f492006-10-04 08:27:25 +020024{
Christoph Hellwig64d513ac2015-10-08 09:28:04 +010025 struct request *req = NULL;
David C Somayajuluf583f492006-10-04 08:27:25 +020026
Christoph Hellwig64d513ac2015-10-08 09:28:04 +010027 if (tag == SCSI_NO_TAG)
28 return NULL;
29
30 if (shost_use_blk_mq(shost)) {
31 u16 hwq = blk_mq_unique_tag_to_hwq(tag);
32
33 if (hwq < shost->tag_set.nr_hw_queues) {
34 req = blk_mq_tag_to_rq(shost->tag_set.tags[hwq],
35 blk_mq_unique_tag_to_tag(tag));
36 }
37 } else {
David C Somayajuluf583f492006-10-04 08:27:25 +020038 req = blk_map_queue_find_tag(shost->bqt, tag);
David C Somayajuluf583f492006-10-04 08:27:25 +020039 }
Christoph Hellwig64d513ac2015-10-08 09:28:04 +010040
41 if (!req)
42 return NULL;
Bart Van Asschebed22132017-08-25 13:46:32 -070043 return blk_mq_rq_to_pdu(req);
David C Somayajuluf583f492006-10-04 08:27:25 +020044}
45
David Howells93614012006-09-30 20:45:40 +020046#endif /* CONFIG_BLOCK */
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#endif /* _SCSI_SCSI_TCQ_H */