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#include <scsi/scsi_host.h>
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)
14
15
16#ifdef CONFIG_BLOCK
17
18
19
20
21
22
23
24
25
26static inline int scsi_get_tag_type(struct scsi_device *sdev)
27{
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;
35}
36
37static inline void scsi_set_tag_type(struct scsi_device *sdev, int tag)
38{
39 switch (tag) {
40 case MSG_ORDERED_TAG:
41 sdev->ordered_tags = 1;
42
43 case MSG_SIMPLE_TAG:
44 sdev->simple_tags = 1;
45 break;
46 case 0:
47
48 default:
49 sdev->ordered_tags = 0;
50 sdev->simple_tags = 0;
51 break;
52 }
53}
54
55
56
57
58
59
60
61
62
63
64static inline void scsi_activate_tcq(struct scsi_device *sdev, int depth)
65{
66 if (!sdev->tagged_supported)
67 return;
68
69 if (!blk_queue_tagged(sdev->request_queue))
70 blk_queue_init_tags(sdev->request_queue, depth,
71 sdev->host->bqt);
72
73 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
74}
75
76
77
78
79
80static inline void scsi_deactivate_tcq(struct scsi_device *sdev, int depth)
81{
82 if (blk_queue_tagged(sdev->request_queue))
83 blk_queue_free_tags(sdev->request_queue);
84 scsi_adjust_queue_depth(sdev, 0, depth);
85}
86
87
88
89
90
91
92
93
94
95
96
97static inline int scsi_populate_tag_msg(struct scsi_cmnd *cmd, char *msg)
98{
99 struct request *req = cmd->request;
100 struct scsi_device *sdev = cmd->device;
101
102 if (blk_rq_tagged(req)) {
103 if (sdev->ordered_tags && req->cmd_flags & REQ_HARDBARRIER)
104 *msg++ = MSG_ORDERED_TAG;
105 else
106 *msg++ = MSG_SIMPLE_TAG;
107 *msg++ = req->tag;
108 return 2;
109 }
110
111 return 0;
112}
113
114
115
116
117
118
119
120
121
122static inline struct scsi_cmnd *scsi_find_tag(struct scsi_device *sdev, int tag)
123{
124
125 struct request *req;
126
127 if (tag != SCSI_NO_TAG) {
128 req = blk_queue_find_tag(sdev->request_queue, tag);
129 return req ? (struct scsi_cmnd *)req->special : NULL;
130 }
131
132
133 return sdev->current_cmnd;
134}
135
136
137
138
139
140
141static inline int scsi_init_shared_tag_map(struct Scsi_Host *shost, int depth)
142{
143
144
145
146
147
148 if (!shost->bqt) {
149 shost->bqt = blk_init_tags(depth);
150 if (!shost->bqt)
151 return -ENOMEM;
152 }
153
154 return 0;
155}
156
157
158
159
160
161
162
163
164
165static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost,
166 int tag)
167{
168 struct request *req;
169
170 if (tag != SCSI_NO_TAG) {
171 req = blk_map_queue_find_tag(shost->bqt, tag);
172 return req ? (struct scsi_cmnd *)req->special : NULL;
173 }
174 return NULL;
175}
176
177#endif
178#endif
179