Merge branch 'v6v7' into devel
[linux/fpc-iii.git] / include / scsi / scsi_tcq.h
blobd6e7994aa634666f1ff072bf2fa96220d4b7e19f
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 MSG_SIMPLE_TAG 0x20
10 #define MSG_HEAD_TAG 0x21
11 #define MSG_ORDERED_TAG 0x22
13 #define SCSI_NO_TAG (-1) /* identify no tag in use */
16 #ifdef CONFIG_BLOCK
18 /**
19 * scsi_get_tag_type - get the type of tag the device supports
20 * @sdev: the scsi device
22 * Notes:
23 * If the drive only supports simple tags, returns MSG_SIMPLE_TAG
24 * if it supports all tag types, returns MSG_ORDERED_TAG.
26 static inline int scsi_get_tag_type(struct scsi_device *sdev)
28 if (!sdev->tagged_supported)
29 return 0;
30 if (sdev->ordered_tags)
31 return MSG_ORDERED_TAG;
32 if (sdev->simple_tags)
33 return MSG_SIMPLE_TAG;
34 return 0;
37 static inline void scsi_set_tag_type(struct scsi_device *sdev, int tag)
39 switch (tag) {
40 case MSG_ORDERED_TAG:
41 sdev->ordered_tags = 1;
42 /* fall through */
43 case MSG_SIMPLE_TAG:
44 sdev->simple_tags = 1;
45 break;
46 case 0:
47 /* fall through */
48 default:
49 sdev->ordered_tags = 0;
50 sdev->simple_tags = 0;
51 break;
54 /**
55 * scsi_activate_tcq - turn on tag command queueing
56 * @SDpnt: device to turn on TCQ for
57 * @depth: queue depth
59 * Notes:
60 * Eventually, I hope depth would be the maximum depth
61 * the device could cope with and the real queue depth
62 * would be adjustable from 0 to depth.
63 **/
64 static inline void scsi_activate_tcq(struct scsi_device *sdev, int depth)
66 if (!sdev->tagged_supported)
67 return;
69 if (!blk_queue_tagged(sdev->request_queue))
70 blk_queue_init_tags(sdev->request_queue, depth,
71 sdev->host->bqt);
73 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
76 /**
77 * scsi_deactivate_tcq - turn off tag command queueing
78 * @SDpnt: device to turn off TCQ for
79 **/
80 static inline void scsi_deactivate_tcq(struct scsi_device *sdev, int depth)
82 if (blk_queue_tagged(sdev->request_queue))
83 blk_queue_free_tags(sdev->request_queue);
84 scsi_adjust_queue_depth(sdev, 0, depth);
87 /**
88 * scsi_populate_tag_msg - place a tag message in a buffer
89 * @SCpnt: pointer to the Scsi_Cmnd for the tag
90 * @msg: pointer to the area to place the tag
92 * Notes:
93 * designed to create the correct type of tag message for the
94 * particular request. Returns the size of the tag message.
95 * May return 0 if TCQ is disabled for this device.
96 **/
97 static inline int scsi_populate_tag_msg(struct scsi_cmnd *cmd, char *msg)
99 struct request *req = cmd->request;
101 if (blk_rq_tagged(req)) {
102 *msg++ = MSG_SIMPLE_TAG;
103 *msg++ = req->tag;
104 return 2;
107 return 0;
111 * scsi_find_tag - find a tagged command by device
112 * @SDpnt: pointer to the ScSI device
113 * @tag: the tag number
115 * Notes:
116 * Only works with tags allocated by the generic blk layer.
118 static inline struct scsi_cmnd *scsi_find_tag(struct scsi_device *sdev, int tag)
121 struct request *req;
123 if (tag != SCSI_NO_TAG) {
124 req = blk_queue_find_tag(sdev->request_queue, tag);
125 return req ? (struct scsi_cmnd *)req->special : NULL;
128 /* single command, look in space */
129 return sdev->current_cmnd;
133 * scsi_init_shared_tag_map - create a shared tag map
134 * @shost: the host to share the tag map among all devices
135 * @depth: the total depth of the map
137 static inline int scsi_init_shared_tag_map(struct Scsi_Host *shost, int depth)
140 * If the shared tag map isn't already initialized, do it now.
141 * This saves callers from having to check ->bqt when setting up
142 * devices on the shared host (for libata)
144 if (!shost->bqt) {
145 shost->bqt = blk_init_tags(depth);
146 if (!shost->bqt)
147 return -ENOMEM;
150 return 0;
154 * scsi_host_find_tag - find the tagged command by host
155 * @shost: pointer to scsi_host
156 * @tag: tag of the scsi_cmnd
158 * Notes:
159 * Only works with tags allocated by the generic blk layer.
161 static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost,
162 int tag)
164 struct request *req;
166 if (tag != SCSI_NO_TAG) {
167 req = blk_map_queue_find_tag(shost->bqt, tag);
168 return req ? (struct scsi_cmnd *)req->special : NULL;
170 return NULL;
173 #endif /* CONFIG_BLOCK */
174 #endif /* _SCSI_SCSI_TCQ_H */