blob: ea7848e74d257e21764c74fe866a5c94a2149a9d [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 Hellwig64d513a2015-10-08 09:28:04 +010017 * @tag: tag
David C Somayajuluf583f492006-10-04 08:27:25 +020018 *
Christoph Hellwig64d513a2015-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 Hellwig64d513a2015-10-08 09:28:04 +010023 int tag)
David C Somayajuluf583f492006-10-04 08:27:25 +020024{
Christoph Hellwig64d513a2015-10-08 09:28:04 +010025 struct request *req = NULL;
Jens Axboef664a3c2018-11-01 16:36:27 -060026 u16 hwq;
David C Somayajuluf583f492006-10-04 08:27:25 +020027
Christoph Hellwig64d513a2015-10-08 09:28:04 +010028 if (tag == SCSI_NO_TAG)
29 return NULL;
30
Jens Axboef664a3c2018-11-01 16:36:27 -060031 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 Somayajuluf583f492006-10-04 08:27:25 +020035 }
Christoph Hellwig64d513a2015-10-08 09:28:04 +010036
Hannes Reineckee73a5e82020-06-22 08:30:22 +020037 if (!req || !blk_mq_request_started(req))
Christoph Hellwig64d513a2015-10-08 09:28:04 +010038 return NULL;
Bart Van Asschebed22132017-08-25 13:46:32 -070039 return blk_mq_rq_to_pdu(req);
David C Somayajuluf583f492006-10-04 08:27:25 +020040}
41
David Howells93614012006-09-30 20:45:40 +020042#endif /* CONFIG_BLOCK */
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#endif /* _SCSI_SCSI_TCQ_H */