Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * zfcp device driver |
| 3 | * |
| 4 | * Header file for zfcp qdio interface |
| 5 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 6 | * Copyright IBM Corp. 2010 |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef ZFCP_QDIO_H |
| 10 | #define ZFCP_QDIO_H |
| 11 | |
| 12 | #include <asm/qdio.h> |
| 13 | |
Christof Schmitt | 6832298 | 2010-04-30 18:09:33 +0200 | [diff] [blame] | 14 | #define ZFCP_QDIO_SBALE_LEN PAGE_SIZE |
| 15 | |
Swen Schillig | 01b0475 | 2010-07-16 15:37:37 +0200 | [diff] [blame] | 16 | /* Max SBALS for chaining */ |
| 17 | #define ZFCP_QDIO_MAX_SBALS_PER_REQ 36 |
| 18 | |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 19 | /** |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 20 | * struct zfcp_qdio - basic qdio data structure |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 21 | * @res_q: response queue |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 22 | * @req_q: request queue |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 23 | * @req_q_idx: index of next free buffer |
| 24 | * @req_q_free: number of free buffers in queue |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 25 | * @stat_lock: lock to protect req_q_util and req_q_time |
| 26 | * @req_q_lock: lock to serialize access to request queue |
| 27 | * @req_q_time: time of last fill level change |
| 28 | * @req_q_util: used for accounting |
| 29 | * @req_q_full: queue full incidents |
| 30 | * @req_q_wq: used to wait for SBAL availability |
| 31 | * @adapter: adapter used in conjunction with this qdio structure |
| 32 | */ |
| 33 | struct zfcp_qdio { |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 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; |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 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; |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 45 | u16 max_sbale_per_sbal; |
| 46 | u16 max_sbale_per_req; |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * struct zfcp_qdio_req - qdio queue related values for a request |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 51 | * @sbtype: sbal type flags for sbale 0 |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 52 | * @sbal_number: number of free sbals |
| 53 | * @sbal_first: first sbal for this request |
| 54 | * @sbal_last: last sbal for this request |
| 55 | * @sbal_limit: last possible sbal for this request |
| 56 | * @sbale_curr: current sbale at creation of this request |
| 57 | * @sbal_response: sbal used in interrupt |
| 58 | * @qdio_outb_usage: usage of outbound queue |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 59 | */ |
| 60 | struct zfcp_qdio_req { |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 61 | u8 sbtype; |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 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; |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | /** |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 72 | * zfcp_qdio_sbale_req - return pointer to sbale on req_q for a request |
| 73 | * @qdio: pointer to struct zfcp_qdio |
| 74 | * @q_rec: pointer to struct zfcp_qdio_req |
| 75 | * Returns: pointer to qdio_buffer_element (sbale) structure |
| 76 | */ |
| 77 | static inline struct qdio_buffer_element * |
| 78 | zfcp_qdio_sbale_req(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req) |
| 79 | { |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 80 | return &qdio->req_q[q_req->sbal_last]->element[0]; |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | /** |
| 84 | * zfcp_qdio_sbale_curr - return current sbale on req_q for a request |
| 85 | * @qdio: pointer to struct zfcp_qdio |
| 86 | * @fsf_req: pointer to struct zfcp_fsf_req |
| 87 | * Returns: pointer to qdio_buffer_element (sbale) structure |
| 88 | */ |
| 89 | static inline struct qdio_buffer_element * |
| 90 | zfcp_qdio_sbale_curr(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req) |
| 91 | { |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 92 | return &qdio->req_q[q_req->sbal_last]->element[q_req->sbale_curr]; |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 95 | /** |
| 96 | * zfcp_qdio_req_init - initialize qdio request |
| 97 | * @qdio: request queue where to start putting the request |
| 98 | * @q_req: the qdio request to start |
| 99 | * @req_id: The request id |
| 100 | * @sbtype: type flags to set for all sbals |
| 101 | * @data: First data block |
| 102 | * @len: Length of first data block |
| 103 | * |
| 104 | * This is the start of putting the request into the queue, the last |
| 105 | * step is passing the request to zfcp_qdio_send. The request queue |
| 106 | * lock must be held during the whole process from init to send. |
| 107 | */ |
| 108 | static inline |
| 109 | void zfcp_qdio_req_init(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 110 | unsigned long req_id, u8 sbtype, void *data, u32 len) |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 111 | { |
| 112 | struct qdio_buffer_element *sbale; |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 113 | int count = min(atomic_read(&qdio->req_q_free), |
Swen Schillig | 01b0475 | 2010-07-16 15:37:37 +0200 | [diff] [blame] | 114 | ZFCP_QDIO_MAX_SBALS_PER_REQ); |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 115 | |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 116 | q_req->sbal_first = q_req->sbal_last = qdio->req_q_idx; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 117 | q_req->sbal_number = 1; |
| 118 | q_req->sbtype = sbtype; |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 119 | q_req->sbale_curr = 1; |
Swen Schillig | 01b0475 | 2010-07-16 15:37:37 +0200 | [diff] [blame] | 120 | q_req->sbal_limit = (q_req->sbal_first + count - 1) |
| 121 | % QDIO_MAX_BUFFERS_PER_Q; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 122 | |
| 123 | sbale = zfcp_qdio_sbale_req(qdio, q_req); |
| 124 | sbale->addr = (void *) req_id; |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 125 | sbale->eflags = 0; |
| 126 | sbale->sflags = SBAL_SFLAGS0_COMMAND | sbtype; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 127 | |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 128 | if (unlikely(!data)) |
| 129 | return; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 130 | sbale++; |
| 131 | sbale->addr = data; |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 132 | sbale->length = len; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /** |
| 136 | * zfcp_qdio_fill_next - Fill next sbale, only for single sbal requests |
| 137 | * @qdio: pointer to struct zfcp_qdio |
| 138 | * @q_req: pointer to struct zfcp_queue_req |
| 139 | * |
| 140 | * This is only required for single sbal requests, calling it when |
| 141 | * wrapping around to the next sbal is a bug. |
| 142 | */ |
| 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 | |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 149 | BUG_ON(q_req->sbale_curr == qdio->max_sbale_per_sbal - 1); |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 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 | * zfcp_qdio_set_sbale_last - set last entry flag in current sbale |
| 158 | * @qdio: pointer to struct zfcp_qdio |
| 159 | * @q_req: pointer to struct zfcp_queue_req |
| 160 | */ |
| 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); |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 168 | sbale->eflags |= SBAL_EFLAGS_LAST_ENTRY; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /** |
| 172 | * zfcp_qdio_sg_one_sbal - check if one sbale is enough for sg data |
| 173 | * @sg: The scatterlist where to check the data size |
| 174 | * |
| 175 | * Returns: 1 when one sbale is enough for the data in the scatterlist, |
| 176 | * 0 if not. |
| 177 | */ |
| 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 | |
| 184 | /** |
| 185 | * zfcp_qdio_skip_to_last_sbale - skip to last sbale in sbal |
| 186 | * @q_req: The current zfcp_qdio_req |
| 187 | */ |
| 188 | static inline |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 189 | void zfcp_qdio_skip_to_last_sbale(struct zfcp_qdio *qdio, |
| 190 | struct zfcp_qdio_req *q_req) |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 191 | { |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 192 | q_req->sbale_curr = qdio->max_sbale_per_sbal - 1; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 193 | } |
| 194 | |
Swen Schillig | 01b0475 | 2010-07-16 15:37:37 +0200 | [diff] [blame] | 195 | /** |
| 196 | * zfcp_qdio_sbal_limit - set the sbal limit for a request in q_req |
| 197 | * @qdio: pointer to struct zfcp_qdio |
| 198 | * @q_req: The current zfcp_qdio_req |
| 199 | * @max_sbals: maximum number of SBALs allowed |
| 200 | */ |
| 201 | static inline |
| 202 | void zfcp_qdio_sbal_limit(struct zfcp_qdio *qdio, |
| 203 | struct zfcp_qdio_req *q_req, int max_sbals) |
| 204 | { |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 205 | int count = min(atomic_read(&qdio->req_q_free), max_sbals); |
Swen Schillig | 01b0475 | 2010-07-16 15:37:37 +0200 | [diff] [blame] | 206 | |
| 207 | q_req->sbal_limit = (q_req->sbal_first + count - 1) % |
| 208 | QDIO_MAX_BUFFERS_PER_Q; |
| 209 | } |
| 210 | |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 211 | /** |
| 212 | * zfcp_qdio_set_data_div - set data division count |
| 213 | * @qdio: pointer to struct zfcp_qdio |
| 214 | * @q_req: The current zfcp_qdio_req |
| 215 | * @count: The data division count |
| 216 | */ |
| 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 | |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 223 | sbale = qdio->req_q[q_req->sbal_first]->element; |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 224 | sbale->length = count; |
| 225 | } |
| 226 | |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 227 | /** |
| 228 | * zfcp_qdio_sbale_count - count sbale used |
| 229 | * @sg: pointer to struct scatterlist |
| 230 | */ |
| 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 | |
| 242 | /** |
| 243 | * zfcp_qdio_real_bytes - count bytes used |
| 244 | * @sg: pointer to struct scatterlist |
| 245 | */ |
| 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 | |
| 257 | /** |
| 258 | * zfcp_qdio_set_scount - set SBAL count value |
| 259 | * @qdio: pointer to struct zfcp_qdio |
| 260 | * @q_req: The current zfcp_qdio_req |
| 261 | */ |
| 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 | |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 271 | #endif /* ZFCP_QDIO_H */ |