1
2
3
4
5
6
7
8
9#ifndef ZFCP_QDIO_H
10#define ZFCP_QDIO_H
11
12#include <asm/qdio.h>
13
14#define ZFCP_QDIO_SBALE_LEN PAGE_SIZE
15
16
17#define ZFCP_QDIO_MAX_SBALS_PER_REQ 36
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33struct zfcp_qdio {
34 struct qdio_buffer *res_q[QDIO_MAX_BUFFERS_PER_Q];
35 struct qdio_buffer *req_q[QDIO_MAX_BUFFERS_PER_Q];
36 u8 req_q_idx;
37 atomic_t req_q_free;
38 spinlock_t stat_lock;
39 spinlock_t req_q_lock;
40 unsigned long long req_q_time;
41 u64 req_q_util;
42 atomic_t req_q_full;
43 wait_queue_head_t req_q_wq;
44 struct zfcp_adapter *adapter;
45 u16 max_sbale_per_sbal;
46 u16 max_sbale_per_req;
47};
48
49
50
51
52
53
54
55
56
57
58
59
60struct zfcp_qdio_req {
61 u8 sbtype;
62 u8 sbal_number;
63 u8 sbal_first;
64 u8 sbal_last;
65 u8 sbal_limit;
66 u8 sbale_curr;
67 u8 sbal_response;
68 u16 qdio_outb_usage;
69};
70
71
72
73
74
75
76
77static inline struct qdio_buffer_element *
78zfcp_qdio_sbale_req(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
79{
80 return &qdio->req_q[q_req->sbal_last]->element[0];
81}
82
83
84
85
86
87
88
89static inline struct qdio_buffer_element *
90zfcp_qdio_sbale_curr(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
91{
92 return &qdio->req_q[q_req->sbal_last]->element[q_req->sbale_curr];
93}
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108static inline
109void zfcp_qdio_req_init(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
110 unsigned long req_id, u8 sbtype, void *data, u32 len)
111{
112 struct qdio_buffer_element *sbale;
113 int count = min(atomic_read(&qdio->req_q_free),
114 ZFCP_QDIO_MAX_SBALS_PER_REQ);
115
116 q_req->sbal_first = q_req->sbal_last = qdio->req_q_idx;
117 q_req->sbal_number = 1;
118 q_req->sbtype = sbtype;
119 q_req->sbale_curr = 1;
120 q_req->sbal_limit = (q_req->sbal_first + count - 1)
121 % QDIO_MAX_BUFFERS_PER_Q;
122
123 sbale = zfcp_qdio_sbale_req(qdio, q_req);
124 sbale->addr = (void *) req_id;
125 sbale->eflags = 0;
126 sbale->sflags = SBAL_SFLAGS0_COMMAND | sbtype;
127
128 if (unlikely(!data))
129 return;
130 sbale++;
131 sbale->addr = data;
132 sbale->length = len;
133}
134
135
136
137
138
139
140
141
142
143static inline
144void zfcp_qdio_fill_next(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
145 void *data, u32 len)
146{
147 struct qdio_buffer_element *sbale;
148
149 BUG_ON(q_req->sbale_curr == qdio->max_sbale_per_sbal - 1);
150 q_req->sbale_curr++;
151 sbale = zfcp_qdio_sbale_curr(qdio, q_req);
152 sbale->addr = data;
153 sbale->length = len;
154}
155
156
157
158
159
160
161static inline
162void zfcp_qdio_set_sbale_last(struct zfcp_qdio *qdio,
163 struct zfcp_qdio_req *q_req)
164{
165 struct qdio_buffer_element *sbale;
166
167 sbale = zfcp_qdio_sbale_curr(qdio, q_req);
168 sbale->eflags |= SBAL_EFLAGS_LAST_ENTRY;
169}
170
171
172
173
174
175
176
177
178static inline
179int zfcp_qdio_sg_one_sbale(struct scatterlist *sg)
180{
181 return sg_is_last(sg) && sg->length <= ZFCP_QDIO_SBALE_LEN;
182}
183
184
185
186
187
188static inline
189void zfcp_qdio_skip_to_last_sbale(struct zfcp_qdio *qdio,
190 struct zfcp_qdio_req *q_req)
191{
192 q_req->sbale_curr = qdio->max_sbale_per_sbal - 1;
193}
194
195
196
197
198
199
200
201static inline
202void zfcp_qdio_sbal_limit(struct zfcp_qdio *qdio,
203 struct zfcp_qdio_req *q_req, int max_sbals)
204{
205 int count = min(atomic_read(&qdio->req_q_free), max_sbals);
206
207 q_req->sbal_limit = (q_req->sbal_first + count - 1) %
208 QDIO_MAX_BUFFERS_PER_Q;
209}
210
211
212
213
214
215
216
217static inline
218void zfcp_qdio_set_data_div(struct zfcp_qdio *qdio,
219 struct zfcp_qdio_req *q_req, u32 count)
220{
221 struct qdio_buffer_element *sbale;
222
223 sbale = qdio->req_q[q_req->sbal_first]->element;
224 sbale->length = count;
225}
226
227
228
229
230
231static inline
232unsigned int zfcp_qdio_sbale_count(struct scatterlist *sg)
233{
234 unsigned int count = 0;
235
236 for (; sg; sg = sg_next(sg))
237 count++;
238
239 return count;
240}
241
242
243
244
245
246static inline
247unsigned int zfcp_qdio_real_bytes(struct scatterlist *sg)
248{
249 unsigned int real_bytes = 0;
250
251 for (; sg; sg = sg_next(sg))
252 real_bytes += sg->length;
253
254 return real_bytes;
255}
256
257
258
259
260
261
262static inline
263void zfcp_qdio_set_scount(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
264{
265 struct qdio_buffer_element *sbale;
266
267 sbale = qdio->req_q[q_req->sbal_first]->element;
268 sbale->scount = q_req->sbal_number - 1;
269}
270
271#endif
272