]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/scsi/scsi_tcq.h
bnx2fc: reduce stack usage in __bnx2fc_enable
[mirror_ubuntu-artful-kernel.git] / include / scsi / scsi_tcq.h
CommitLineData
1da177e4
LT
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>
86e33a29 7#include <scsi/scsi_host.h>
1da177e4 8
1da177e4
LT
9#define SCSI_NO_TAG (-1) /* identify no tag in use */
10
11
9361401e 12#ifdef CONFIG_BLOCK
d285203c 13static inline struct scsi_cmnd *scsi_mq_find_tag(struct Scsi_Host *shost,
1ee8e889 14 int unique_tag)
d285203c 15{
1ee8e889
BVA
16 u16 hwq = blk_mq_unique_tag_to_hwq(unique_tag);
17 struct request *req = NULL;
d285203c 18
1ee8e889
BVA
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));
d285203c
CH
22 return req ? (struct scsi_cmnd *)req->special : NULL;
23}
24
1da177e4
LT
25/**
26 * scsi_find_tag - find a tagged command by device
27 * @SDpnt: pointer to the ScSI device
1ee8e889 28 * @tag: tag generated by blk_mq_unique_tag()
1da177e4
LT
29 *
30 * Notes:
31 * Only works with tags allocated by the generic blk layer.
32 **/
33static inline struct scsi_cmnd *scsi_find_tag(struct scsi_device *sdev, int tag)
34{
1da177e4
LT
35 struct request *req;
36
37 if (tag != SCSI_NO_TAG) {
d285203c 38 if (shost_use_blk_mq(sdev->host))
1ee8e889 39 return scsi_mq_find_tag(sdev->host, tag);
d285203c 40
1ee8e889 41 req = blk_queue_find_tag(sdev->request_queue, tag);
1da177e4
LT
42 return req ? (struct scsi_cmnd *)req->special : NULL;
43 }
44
45 /* single command, look in space */
46 return sdev->current_cmnd;
47}
48
d285203c 49
86e33a29
JB
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 */
deb81d80 55static inline int scsi_init_shared_tag_map(struct Scsi_Host *shost, int depth)
86e33a29 56{
d285203c
CH
57 /*
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
3070f69b
JA
63 /*
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) {
ee1b6f7a
SL
69 shost->bqt = blk_init_tags(depth,
70 shost->hostt->tag_alloc_policy);
3070f69b
JA
71 if (!shost->bqt)
72 return -ENOMEM;
73 }
74
75 return 0;
86e33a29
JB
76}
77
f583f492
DS
78/**
79 * scsi_host_find_tag - find the tagged command by host
80 * @shost: pointer to scsi_host
1ee8e889 81 * @tag: tag generated by blk_mq_unique_tag()
f583f492
DS
82 *
83 * Notes:
84 * Only works with tags allocated by the generic blk layer.
85 **/
86static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost,
87 int tag)
88{
89 struct request *req;
90
91 if (tag != SCSI_NO_TAG) {
d285203c 92 if (shost_use_blk_mq(shost))
1ee8e889 93 return scsi_mq_find_tag(shost, tag);
f583f492
DS
94 req = blk_map_queue_find_tag(shost->bqt, tag);
95 return req ? (struct scsi_cmnd *)req->special : NULL;
96 }
97 return NULL;
98}
99
9361401e 100#endif /* CONFIG_BLOCK */
1da177e4 101#endif /* _SCSI_SCSI_TCQ_H */