Merge tag 'kvm-riscv-6.4-1' of https://github.com/kvm-riscv/linux into HEAD
[linux-block.git] / include / scsi / scsi_tcq.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
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>
86e33a29 8#include <scsi/scsi_host.h>
1da177e4 9
1da177e4
LT
10#define SCSI_NO_TAG (-1) /* identify no tag in use */
11
12
9361401e 13#ifdef CONFIG_BLOCK
f583f492
DS
14/**
15 * scsi_host_find_tag - find the tagged command by host
16 * @shost: pointer to scsi_host
64d513ac 17 * @tag: tag
f583f492 18 *
64d513ac
CH
19 * Note: for devices using multiple hardware queues tag must have been
20 * generated by blk_mq_unique_tag().
f583f492
DS
21 **/
22static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost,
64d513ac 23 int tag)
f583f492 24{
64d513ac 25 struct request *req = NULL;
f664a3cc 26 u16 hwq;
f583f492 27
64d513ac
CH
28 if (tag == SCSI_NO_TAG)
29 return NULL;
30
f664a3cc
JA
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));
f583f492 35 }
64d513ac 36
e73a5e8e 37 if (!req || !blk_mq_request_started(req))
64d513ac 38 return NULL;
bed2213d 39 return blk_mq_rq_to_pdu(req);
f583f492
DS
40}
41
9361401e 42#endif /* CONFIG_BLOCK */
1da177e4 43#endif /* _SCSI_SCSI_TCQ_H */