ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / scsi / scsi_tcq.h
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>
7
8
9 #define MSG_SIMPLE_TAG  0x20
10 #define MSG_HEAD_TAG    0x21
11 #define MSG_ORDERED_TAG 0x22
12
13 #define SCSI_NO_TAG     (-1)    /* identify no tag in use */
14
15
16 /**
17  * scsi_activate_tcq - turn on tag command queueing
18  * @SDpnt:      device to turn on TCQ for
19  * @depth:      queue depth
20  *
21  * Notes:
22  *      Eventually, I hope depth would be the maximum depth
23  *      the device could cope with and the real queue depth
24  *      would be adjustable from 0 to depth.
25  **/
26 static inline void scsi_activate_tcq(struct scsi_device *sdev, int depth)
27 {
28         if (sdev->tagged_supported) {
29                 if (!blk_queue_tagged(sdev->request_queue))
30                         blk_queue_init_tags(sdev->request_queue, depth, NULL);
31                 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, depth);
32         }
33 }
34
35 /**
36  * scsi_deactivate_tcq - turn off tag command queueing
37  * @SDpnt:      device to turn off TCQ for
38  **/
39 static inline void scsi_deactivate_tcq(struct scsi_device *sdev, int depth)
40 {
41         if (blk_queue_tagged(sdev->request_queue))
42                 blk_queue_free_tags(sdev->request_queue);
43         scsi_adjust_queue_depth(sdev, 0, depth);
44 }
45
46 /**
47  * scsi_populate_tag_msg - place a tag message in a buffer
48  * @SCpnt:      pointer to the Scsi_Cmnd for the tag
49  * @msg:        pointer to the area to place the tag
50  *
51  * Notes:
52  *      designed to create the correct type of tag message for the 
53  *      particular request.  Returns the size of the tag message.
54  *      May return 0 if TCQ is disabled for this device.
55  **/
56 static inline int scsi_populate_tag_msg(struct scsi_cmnd *cmd, char *msg)
57 {
58         struct request *req = cmd->request;
59
60         if (blk_rq_tagged(req)) {
61                 if (req->flags & REQ_HARDBARRIER)
62                         *msg++ = MSG_ORDERED_TAG;
63                 else
64                         *msg++ = MSG_SIMPLE_TAG;
65                 *msg++ = req->tag;
66                 return 2;
67         }
68
69         return 0;
70 }
71
72 /**
73  * scsi_find_tag - find a tagged command by device
74  * @SDpnt:      pointer to the ScSI device
75  * @tag:        the tag number
76  *
77  * Notes:
78  *      Only works with tags allocated by the generic blk layer.
79  **/
80 static inline struct scsi_cmnd *scsi_find_tag(struct scsi_device *sdev, int tag)
81 {
82
83         struct request *req;
84
85         if (tag != SCSI_NO_TAG) {
86                 req = blk_queue_find_tag(sdev->request_queue, tag);
87                 return req ? (struct scsi_cmnd *)req->special : NULL;
88         }
89
90         /* single command, look in space */
91         return sdev->current_cmnd;
92 }
93
94 #endif /* _SCSI_SCSI_TCQ_H */