gpio: tc3589x: use static container helper
[linux/fpc-iii.git] / include / scsi / scsi_tcq.h
blobb27977e8aaed9b12bf6497fbdf01879a47b26cbc
1 #ifndef _SCSI_SCSI_TCQ_H
2 #define _SCSI_SCSI_TCQ_H
4 #include <linux/blkdev.h>
5 #include <scsi/scsi_cmnd.h>
6 #include <scsi/scsi_device.h>
7 #include <scsi/scsi_host.h>
9 #define SCSI_NO_TAG (-1) /* identify no tag in use */
12 #ifdef CONFIG_BLOCK
13 static inline struct scsi_cmnd *scsi_mq_find_tag(struct Scsi_Host *shost,
14 int unique_tag)
16 u16 hwq = blk_mq_unique_tag_to_hwq(unique_tag);
17 struct request *req = NULL;
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));
22 return req ? (struct scsi_cmnd *)req->special : NULL;
25 /**
26 * scsi_find_tag - find a tagged command by device
27 * @SDpnt: pointer to the ScSI device
28 * @tag: tag generated by blk_mq_unique_tag()
30 * Notes:
31 * Only works with tags allocated by the generic blk layer.
32 **/
33 static inline struct scsi_cmnd *scsi_find_tag(struct scsi_device *sdev, int tag)
35 struct request *req;
37 if (tag != SCSI_NO_TAG) {
38 if (shost_use_blk_mq(sdev->host))
39 return scsi_mq_find_tag(sdev->host, tag);
41 req = blk_queue_find_tag(sdev->request_queue, tag);
42 return req ? (struct scsi_cmnd *)req->special : NULL;
45 /* single command, look in space */
46 return sdev->current_cmnd;
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
55 static inline int scsi_init_shared_tag_map(struct Scsi_Host *shost, int depth)
58 * We always have a shared tag map around when using blk-mq.
60 if (shost_use_blk_mq(shost))
61 return 0;
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)
68 if (!shost->bqt) {
69 shost->bqt = blk_init_tags(depth,
70 shost->hostt->tag_alloc_policy);
71 if (!shost->bqt)
72 return -ENOMEM;
75 return 0;
78 /**
79 * scsi_host_find_tag - find the tagged command by host
80 * @shost: pointer to scsi_host
81 * @tag: tag generated by blk_mq_unique_tag()
83 * Notes:
84 * Only works with tags allocated by the generic blk layer.
85 **/
86 static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost,
87 int tag)
89 struct request *req;
91 if (tag != SCSI_NO_TAG) {
92 if (shost_use_blk_mq(shost))
93 return scsi_mq_find_tag(shost, tag);
94 req = blk_map_queue_find_tag(shost->bqt, tag);
95 return req ? (struct scsi_cmnd *)req->special : NULL;
97 return NULL;
100 #endif /* CONFIG_BLOCK */
101 #endif /* _SCSI_SCSI_TCQ_H */