WIP FPC-III support
[linux/fpc-iii.git] / drivers / s390 / scsi / zfcp_qdio.h
blob9c1f310db1551b8a077dddf599276388004bd2ae
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * zfcp device driver
5 * Header file for zfcp qdio interface
7 * Copyright IBM Corp. 2010
8 */
10 #ifndef ZFCP_QDIO_H
11 #define ZFCP_QDIO_H
13 #include <linux/interrupt.h>
14 #include <asm/qdio.h>
16 #define ZFCP_QDIO_SBALE_LEN PAGE_SIZE
18 /* Max SBALS for chaining */
19 #define ZFCP_QDIO_MAX_SBALS_PER_REQ 36
21 /**
22 * struct zfcp_qdio - basic qdio data structure
23 * @res_q: response queue
24 * @req_q: request queue
25 * @req_q_idx: index of next free buffer
26 * @req_q_free: number of free buffers in queue
27 * @stat_lock: lock to protect req_q_util and req_q_time
28 * @req_q_lock: lock to serialize access to request queue
29 * @req_q_time: time of last fill level change
30 * @req_q_util: used for accounting
31 * @req_q_full: queue full incidents
32 * @req_q_wq: used to wait for SBAL availability
33 * @adapter: adapter used in conjunction with this qdio structure
34 * @max_sbale_per_sbal: qdio limit per sbal
35 * @max_sbale_per_req: qdio limit per request
37 struct zfcp_qdio {
38 struct qdio_buffer *res_q[QDIO_MAX_BUFFERS_PER_Q];
39 struct qdio_buffer *req_q[QDIO_MAX_BUFFERS_PER_Q];
40 u8 req_q_idx;
41 atomic_t req_q_free;
42 spinlock_t stat_lock;
43 spinlock_t req_q_lock;
44 unsigned long long req_q_time;
45 u64 req_q_util;
46 atomic_t req_q_full;
47 wait_queue_head_t req_q_wq;
48 struct tasklet_struct irq_tasklet;
49 struct zfcp_adapter *adapter;
50 u16 max_sbale_per_sbal;
51 u16 max_sbale_per_req;
54 /**
55 * struct zfcp_qdio_req - qdio queue related values for a request
56 * @sbtype: sbal type flags for sbale 0
57 * @sbal_number: number of free sbals
58 * @sbal_first: first sbal for this request
59 * @sbal_last: last sbal for this request
60 * @sbal_limit: last possible sbal for this request
61 * @sbale_curr: current sbale at creation of this request
62 * @qdio_outb_usage: usage of outbound queue
64 struct zfcp_qdio_req {
65 u8 sbtype;
66 u8 sbal_number;
67 u8 sbal_first;
68 u8 sbal_last;
69 u8 sbal_limit;
70 u8 sbale_curr;
71 u16 qdio_outb_usage;
74 /**
75 * zfcp_qdio_sbale_req - return pointer to sbale on req_q for a request
76 * @qdio: pointer to struct zfcp_qdio
77 * @q_req: pointer to struct zfcp_qdio_req
78 * Returns: pointer to qdio_buffer_element (sbale) structure
80 static inline struct qdio_buffer_element *
81 zfcp_qdio_sbale_req(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
83 return &qdio->req_q[q_req->sbal_last]->element[0];
86 /**
87 * zfcp_qdio_sbale_curr - return current sbale on req_q for a request
88 * @qdio: pointer to struct zfcp_qdio
89 * @q_req: pointer to struct zfcp_qdio_req
90 * Returns: pointer to qdio_buffer_element (sbale) structure
92 static inline struct qdio_buffer_element *
93 zfcp_qdio_sbale_curr(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
95 return &qdio->req_q[q_req->sbal_last]->element[q_req->sbale_curr];
98 /**
99 * zfcp_qdio_req_init - initialize qdio request
100 * @qdio: request queue where to start putting the request
101 * @q_req: the qdio request to start
102 * @req_id: The request id
103 * @sbtype: type flags to set for all sbals
104 * @data: First data block
105 * @len: Length of first data block
107 * This is the start of putting the request into the queue, the last
108 * step is passing the request to zfcp_qdio_send. The request queue
109 * lock must be held during the whole process from init to send.
111 static inline
112 void zfcp_qdio_req_init(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
113 unsigned long req_id, u8 sbtype, void *data, u32 len)
115 struct qdio_buffer_element *sbale;
116 int count = min(atomic_read(&qdio->req_q_free),
117 ZFCP_QDIO_MAX_SBALS_PER_REQ);
119 q_req->sbal_first = q_req->sbal_last = qdio->req_q_idx;
120 q_req->sbal_number = 1;
121 q_req->sbtype = sbtype;
122 q_req->sbale_curr = 1;
123 q_req->sbal_limit = (q_req->sbal_first + count - 1)
124 % QDIO_MAX_BUFFERS_PER_Q;
126 sbale = zfcp_qdio_sbale_req(qdio, q_req);
127 sbale->addr = req_id;
128 sbale->eflags = 0;
129 sbale->sflags = SBAL_SFLAGS0_COMMAND | sbtype;
131 if (unlikely(!data))
132 return;
133 sbale++;
134 sbale->addr = virt_to_phys(data);
135 sbale->length = len;
139 * zfcp_qdio_fill_next - Fill next sbale, only for single sbal requests
140 * @qdio: pointer to struct zfcp_qdio
141 * @q_req: pointer to struct zfcp_queue_req
142 * @data: pointer to data
143 * @len: length of data
145 * This is only required for single sbal requests, calling it when
146 * wrapping around to the next sbal is a bug.
148 static inline
149 void zfcp_qdio_fill_next(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
150 void *data, u32 len)
152 struct qdio_buffer_element *sbale;
154 BUG_ON(q_req->sbale_curr == qdio->max_sbale_per_sbal - 1);
155 q_req->sbale_curr++;
156 sbale = zfcp_qdio_sbale_curr(qdio, q_req);
157 sbale->addr = virt_to_phys(data);
158 sbale->length = len;
162 * zfcp_qdio_set_sbale_last - set last entry flag in current sbale
163 * @qdio: pointer to struct zfcp_qdio
164 * @q_req: pointer to struct zfcp_queue_req
166 static inline
167 void zfcp_qdio_set_sbale_last(struct zfcp_qdio *qdio,
168 struct zfcp_qdio_req *q_req)
170 struct qdio_buffer_element *sbale;
172 sbale = zfcp_qdio_sbale_curr(qdio, q_req);
173 sbale->eflags |= SBAL_EFLAGS_LAST_ENTRY;
177 * zfcp_qdio_sg_one_sbal - check if one sbale is enough for sg data
178 * @sg: The scatterlist where to check the data size
180 * Returns: 1 when one sbale is enough for the data in the scatterlist,
181 * 0 if not.
183 static inline
184 int zfcp_qdio_sg_one_sbale(struct scatterlist *sg)
186 return sg_is_last(sg) && sg->length <= ZFCP_QDIO_SBALE_LEN;
190 * zfcp_qdio_skip_to_last_sbale - skip to last sbale in sbal
191 * @qdio: pointer to struct zfcp_qdio
192 * @q_req: The current zfcp_qdio_req
194 static inline
195 void zfcp_qdio_skip_to_last_sbale(struct zfcp_qdio *qdio,
196 struct zfcp_qdio_req *q_req)
198 q_req->sbale_curr = qdio->max_sbale_per_sbal - 1;
202 * zfcp_qdio_sbal_limit - set the sbal limit for a request in q_req
203 * @qdio: pointer to struct zfcp_qdio
204 * @q_req: The current zfcp_qdio_req
205 * @max_sbals: maximum number of SBALs allowed
207 static inline
208 void zfcp_qdio_sbal_limit(struct zfcp_qdio *qdio,
209 struct zfcp_qdio_req *q_req, int max_sbals)
211 int count = min(atomic_read(&qdio->req_q_free), max_sbals);
213 q_req->sbal_limit = (q_req->sbal_first + count - 1) %
214 QDIO_MAX_BUFFERS_PER_Q;
218 * zfcp_qdio_set_data_div - set data division count
219 * @qdio: pointer to struct zfcp_qdio
220 * @q_req: The current zfcp_qdio_req
221 * @count: The data division count
223 static inline
224 void zfcp_qdio_set_data_div(struct zfcp_qdio *qdio,
225 struct zfcp_qdio_req *q_req, u32 count)
227 struct qdio_buffer_element *sbale;
229 sbale = qdio->req_q[q_req->sbal_first]->element;
230 sbale->length = count;
234 * zfcp_qdio_real_bytes - count bytes used
235 * @sg: pointer to struct scatterlist
237 static inline
238 unsigned int zfcp_qdio_real_bytes(struct scatterlist *sg)
240 unsigned int real_bytes = 0;
242 for (; sg; sg = sg_next(sg))
243 real_bytes += sg->length;
245 return real_bytes;
249 * zfcp_qdio_set_scount - set SBAL count value
250 * @qdio: pointer to struct zfcp_qdio
251 * @q_req: The current zfcp_qdio_req
253 static inline
254 void zfcp_qdio_set_scount(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
256 struct qdio_buffer_element *sbale;
258 sbale = qdio->req_q[q_req->sbal_first]->element;
259 sbale->scount = q_req->sbal_number - 1;
262 #endif /* ZFCP_QDIO_H */