of/gpio: fix of_gpio includes
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / s390 / scsi / zfcp_qdio.h
blob138fba577b48c5f09f1ce1e7636fc8ee8d0d86c0
1 /*
2 * zfcp device driver
4 * Header file for zfcp qdio interface
6 * Copyright IBM Corporation 2010
7 */
9 #ifndef ZFCP_QDIO_H
10 #define ZFCP_QDIO_H
12 #include <asm/qdio.h>
14 #define ZFCP_QDIO_SBALE_LEN PAGE_SIZE
16 /* DMQ bug workaround: don't use last SBALE */
17 #define ZFCP_QDIO_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
19 /* index of last SBALE (with respect to DMQ bug workaround) */
20 #define ZFCP_QDIO_LAST_SBALE_PER_SBAL (ZFCP_QDIO_MAX_SBALES_PER_SBAL - 1)
22 /**
23 * struct zfcp_qdio_queue - qdio queue buffer, zfcp index and free count
24 * @sbal: qdio buffers
25 * @first: index of next free buffer in queue
26 * @count: number of free buffers in queue
28 struct zfcp_qdio_queue {
29 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q];
30 u8 first;
31 atomic_t count;
34 /**
35 * struct zfcp_qdio - basic qdio data structure
36 * @resp_q: response queue
37 * @req_q: request queue
38 * @stat_lock: lock to protect req_q_util and req_q_time
39 * @req_q_lock: lock to serialize access to request queue
40 * @req_q_time: time of last fill level change
41 * @req_q_util: used for accounting
42 * @req_q_full: queue full incidents
43 * @req_q_wq: used to wait for SBAL availability
44 * @adapter: adapter used in conjunction with this qdio structure
46 struct zfcp_qdio {
47 struct zfcp_qdio_queue resp_q;
48 struct zfcp_qdio_queue req_q;
49 spinlock_t stat_lock;
50 spinlock_t req_q_lock;
51 unsigned long long req_q_time;
52 u64 req_q_util;
53 atomic_t req_q_full;
54 wait_queue_head_t req_q_wq;
55 struct zfcp_adapter *adapter;
58 /**
59 * struct zfcp_qdio_req - qdio queue related values for a request
60 * @sbtype: sbal type flags for sbale 0
61 * @sbal_number: number of free sbals
62 * @sbal_first: first sbal for this request
63 * @sbal_last: last sbal for this request
64 * @sbal_limit: last possible sbal for this request
65 * @sbale_curr: current sbale at creation of this request
66 * @sbal_response: sbal used in interrupt
67 * @qdio_outb_usage: usage of outbound queue
68 * @qdio_inb_usage: usage of inbound queue
70 struct zfcp_qdio_req {
71 u32 sbtype;
72 u8 sbal_number;
73 u8 sbal_first;
74 u8 sbal_last;
75 u8 sbal_limit;
76 u8 sbale_curr;
77 u8 sbal_response;
78 u16 qdio_outb_usage;
79 u16 qdio_inb_usage;
82 /**
83 * zfcp_qdio_sbale - return pointer to sbale in qdio queue
84 * @q: queue where to find sbal
85 * @sbal_idx: sbal index in queue
86 * @sbale_idx: sbale index in sbal
88 static inline struct qdio_buffer_element *
89 zfcp_qdio_sbale(struct zfcp_qdio_queue *q, int sbal_idx, int sbale_idx)
91 return &q->sbal[sbal_idx]->element[sbale_idx];
94 /**
95 * zfcp_qdio_sbale_req - return pointer to sbale on req_q for a request
96 * @qdio: pointer to struct zfcp_qdio
97 * @q_rec: pointer to struct zfcp_qdio_req
98 * Returns: pointer to qdio_buffer_element (sbale) structure
100 static inline struct qdio_buffer_element *
101 zfcp_qdio_sbale_req(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
103 return zfcp_qdio_sbale(&qdio->req_q, q_req->sbal_last, 0);
107 * zfcp_qdio_sbale_curr - return current sbale on req_q for a request
108 * @qdio: pointer to struct zfcp_qdio
109 * @fsf_req: pointer to struct zfcp_fsf_req
110 * Returns: pointer to qdio_buffer_element (sbale) structure
112 static inline struct qdio_buffer_element *
113 zfcp_qdio_sbale_curr(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
115 return zfcp_qdio_sbale(&qdio->req_q, q_req->sbal_last,
116 q_req->sbale_curr);
120 * zfcp_qdio_req_init - initialize qdio request
121 * @qdio: request queue where to start putting the request
122 * @q_req: the qdio request to start
123 * @req_id: The request id
124 * @sbtype: type flags to set for all sbals
125 * @data: First data block
126 * @len: Length of first data block
128 * This is the start of putting the request into the queue, the last
129 * step is passing the request to zfcp_qdio_send. The request queue
130 * lock must be held during the whole process from init to send.
132 static inline
133 void zfcp_qdio_req_init(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
134 unsigned long req_id, u32 sbtype, void *data, u32 len)
136 struct qdio_buffer_element *sbale;
138 q_req->sbal_first = q_req->sbal_last = qdio->req_q.first;
139 q_req->sbal_number = 1;
140 q_req->sbtype = sbtype;
142 sbale = zfcp_qdio_sbale_req(qdio, q_req);
143 sbale->addr = (void *) req_id;
144 sbale->flags |= SBAL_FLAGS0_COMMAND;
145 sbale->flags |= sbtype;
147 q_req->sbale_curr = 1;
148 sbale++;
149 sbale->addr = data;
150 if (likely(data))
151 sbale->length = len;
155 * zfcp_qdio_fill_next - Fill next sbale, only for single sbal requests
156 * @qdio: pointer to struct zfcp_qdio
157 * @q_req: pointer to struct zfcp_queue_req
159 * This is only required for single sbal requests, calling it when
160 * wrapping around to the next sbal is a bug.
162 static inline
163 void zfcp_qdio_fill_next(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
164 void *data, u32 len)
166 struct qdio_buffer_element *sbale;
168 BUG_ON(q_req->sbale_curr == ZFCP_QDIO_LAST_SBALE_PER_SBAL);
169 q_req->sbale_curr++;
170 sbale = zfcp_qdio_sbale_curr(qdio, q_req);
171 sbale->addr = data;
172 sbale->length = len;
176 * zfcp_qdio_set_sbale_last - set last entry flag in current sbale
177 * @qdio: pointer to struct zfcp_qdio
178 * @q_req: pointer to struct zfcp_queue_req
180 static inline
181 void zfcp_qdio_set_sbale_last(struct zfcp_qdio *qdio,
182 struct zfcp_qdio_req *q_req)
184 struct qdio_buffer_element *sbale;
186 sbale = zfcp_qdio_sbale_curr(qdio, q_req);
187 sbale->flags |= SBAL_FLAGS_LAST_ENTRY;
191 * zfcp_qdio_sg_one_sbal - check if one sbale is enough for sg data
192 * @sg: The scatterlist where to check the data size
194 * Returns: 1 when one sbale is enough for the data in the scatterlist,
195 * 0 if not.
197 static inline
198 int zfcp_qdio_sg_one_sbale(struct scatterlist *sg)
200 return sg_is_last(sg) && sg->length <= ZFCP_QDIO_SBALE_LEN;
204 * zfcp_qdio_skip_to_last_sbale - skip to last sbale in sbal
205 * @q_req: The current zfcp_qdio_req
207 static inline
208 void zfcp_qdio_skip_to_last_sbale(struct zfcp_qdio_req *q_req)
210 q_req->sbale_curr = ZFCP_QDIO_LAST_SBALE_PER_SBAL;
213 #endif /* ZFCP_QDIO_H */