Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
zfcp_qdio.h
Go to the documentation of this file.
1 /*
2  * zfcp device driver
3  *
4  * Header file for zfcp qdio interface
5  *
6  * Copyright IBM Corp. 2010
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 /* Max SBALS for chaining */
17 #define ZFCP_QDIO_MAX_SBALS_PER_REQ 36
18 
33 struct zfcp_qdio {
40  unsigned long long req_q_time;
47 };
48 
60 struct zfcp_qdio_req {
69 };
70 
77 static inline struct qdio_buffer_element *
78 zfcp_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 
89 static inline struct qdio_buffer_element *
90 zfcp_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 
108 static inline
109 void 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),
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)
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 
143 static inline
144 void 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 
161 static inline
162 void 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 
178 static inline
179 int zfcp_qdio_sg_one_sbale(struct scatterlist *sg)
180 {
181  return sg_is_last(sg) && sg->length <= ZFCP_QDIO_SBALE_LEN;
182 }
183 
188 static inline
189 void 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 
201 static inline
202 void 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) %
209 }
210 
217 static inline
218 void 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 
231 static inline
232 unsigned 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 
246 static inline
247 unsigned 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 
262 static inline
263 void 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 /* ZFCP_QDIO_H */