]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
00bab910 | 2 | * zfcp device driver |
1da177e4 | 3 | * |
00bab910 | 4 | * Setup and helper functions to access QDIO. |
1da177e4 | 5 | * |
1674b405 | 6 | * Copyright IBM Corporation 2002, 2010 |
1da177e4 LT |
7 | */ |
8 | ||
ecf39d42 CS |
9 | #define KMSG_COMPONENT "zfcp" |
10 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | |
11 | ||
5a0e3ad6 | 12 | #include <linux/slab.h> |
1da177e4 | 13 | #include "zfcp_ext.h" |
34c2b712 | 14 | #include "zfcp_qdio.h" |
1da177e4 | 15 | |
5d4e2262 | 16 | #define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer)) |
1da177e4 | 17 | |
00bab910 | 18 | static int zfcp_qdio_buffers_enqueue(struct qdio_buffer **sbal) |
1da177e4 | 19 | { |
b4e44590 | 20 | int pos; |
1da177e4 | 21 | |
b4e44590 | 22 | for (pos = 0; pos < QDIO_MAX_BUFFERS_PER_Q; pos += QBUFF_PER_PAGE) { |
00bab910 SS |
23 | sbal[pos] = (struct qdio_buffer *) get_zeroed_page(GFP_KERNEL); |
24 | if (!sbal[pos]) | |
b4e44590 | 25 | return -ENOMEM; |
b4e44590 SS |
26 | } |
27 | for (pos = 0; pos < QDIO_MAX_BUFFERS_PER_Q; pos++) | |
28 | if (pos % QBUFF_PER_PAGE) | |
00bab910 | 29 | sbal[pos] = sbal[pos - 1] + 1; |
b4e44590 | 30 | return 0; |
1da177e4 LT |
31 | } |
32 | ||
339f4f4e CS |
33 | static void zfcp_qdio_handler_error(struct zfcp_qdio *qdio, char *id, |
34 | unsigned int qdio_err) | |
1da177e4 | 35 | { |
564e1c86 SS |
36 | struct zfcp_adapter *adapter = qdio->adapter; |
37 | ||
ff3b24fa | 38 | dev_warn(&adapter->ccw_device->dev, "A QDIO problem occurred\n"); |
1da177e4 | 39 | |
339f4f4e CS |
40 | if (qdio_err & QDIO_ERROR_SLSB_STATE) |
41 | zfcp_qdio_siosl(adapter); | |
00bab910 SS |
42 | zfcp_erp_adapter_reopen(adapter, |
43 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | | |
ea4a3a6a | 44 | ZFCP_STATUS_COMMON_ERP_FAILED, id); |
1da177e4 LT |
45 | } |
46 | ||
5d4e2262 CS |
47 | static void zfcp_qdio_zero_sbals(struct qdio_buffer *sbal[], int first, int cnt) |
48 | { | |
49 | int i, sbal_idx; | |
50 | ||
51 | for (i = first; i < first + cnt; i++) { | |
52 | sbal_idx = i % QDIO_MAX_BUFFERS_PER_Q; | |
53 | memset(sbal[sbal_idx], 0, sizeof(struct qdio_buffer)); | |
54 | } | |
55 | } | |
56 | ||
94506fd1 | 57 | /* this needs to be called prior to updating the queue fill level */ |
41e05a12 | 58 | static inline void zfcp_qdio_account(struct zfcp_qdio *qdio) |
94506fd1 | 59 | { |
41e05a12 | 60 | unsigned long long now, span; |
706eca49 | 61 | int used; |
94506fd1 | 62 | |
41e05a12 HC |
63 | now = get_clock_monotonic(); |
64 | span = (now - qdio->req_q_time) >> 12; | |
706eca49 | 65 | used = QDIO_MAX_BUFFERS_PER_Q - atomic_read(&qdio->req_q_free); |
564e1c86 SS |
66 | qdio->req_q_util += used * span; |
67 | qdio->req_q_time = now; | |
94506fd1 MP |
68 | } |
69 | ||
779e6e1c | 70 | static void zfcp_qdio_int_req(struct ccw_device *cdev, unsigned int qdio_err, |
706eca49 | 71 | int queue_no, int idx, int count, |
00bab910 | 72 | unsigned long parm) |
1da177e4 | 73 | { |
564e1c86 | 74 | struct zfcp_qdio *qdio = (struct zfcp_qdio *) parm; |
1da177e4 | 75 | |
779e6e1c | 76 | if (unlikely(qdio_err)) { |
339f4f4e | 77 | zfcp_qdio_handler_error(qdio, "qdireq1", qdio_err); |
00bab910 SS |
78 | return; |
79 | } | |
1da177e4 LT |
80 | |
81 | /* cleanup all SBALs being program-owned now */ | |
706eca49 | 82 | zfcp_qdio_zero_sbals(qdio->req_q, idx, count); |
1da177e4 | 83 | |
44a24cb3 | 84 | spin_lock_irq(&qdio->stat_lock); |
564e1c86 | 85 | zfcp_qdio_account(qdio); |
44a24cb3 | 86 | spin_unlock_irq(&qdio->stat_lock); |
706eca49 | 87 | atomic_add(count, &qdio->req_q_free); |
564e1c86 | 88 | wake_up(&qdio->req_q_wq); |
1da177e4 LT |
89 | } |
90 | ||
779e6e1c | 91 | static void zfcp_qdio_int_resp(struct ccw_device *cdev, unsigned int qdio_err, |
706eca49 | 92 | int queue_no, int idx, int count, |
00bab910 SS |
93 | unsigned long parm) |
94 | { | |
564e1c86 | 95 | struct zfcp_qdio *qdio = (struct zfcp_qdio *) parm; |
bd63eaf4 | 96 | int sbal_idx, sbal_no; |
00bab910 | 97 | |
779e6e1c | 98 | if (unlikely(qdio_err)) { |
339f4f4e | 99 | zfcp_qdio_handler_error(qdio, "qdires1", qdio_err); |
00bab910 SS |
100 | return; |
101 | } | |
1da177e4 | 102 | |
1da177e4 LT |
103 | /* |
104 | * go through all SBALs from input queue currently | |
105 | * returned by QDIO layer | |
106 | */ | |
00bab910 | 107 | for (sbal_no = 0; sbal_no < count; sbal_no++) { |
706eca49 | 108 | sbal_idx = (idx + sbal_no) % QDIO_MAX_BUFFERS_PER_Q; |
1da177e4 | 109 | /* go through all SBALEs of SBAL */ |
564e1c86 | 110 | zfcp_fsf_reqid_check(qdio, sbal_idx); |
1da177e4 LT |
111 | } |
112 | ||
113 | /* | |
706eca49 | 114 | * put SBALs back to response queue |
1da177e4 | 115 | */ |
706eca49 | 116 | if (do_QDIO(cdev, QDIO_FLAG_SYNC_INPUT, 0, idx, count)) |
ea4a3a6a | 117 | zfcp_erp_adapter_reopen(qdio->adapter, 0, "qdires2"); |
1da177e4 LT |
118 | } |
119 | ||
44cc76f2 | 120 | static struct qdio_buffer_element * |
1674b405 | 121 | zfcp_qdio_sbal_chain(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req) |
1da177e4 | 122 | { |
44cc76f2 | 123 | struct qdio_buffer_element *sbale; |
1da177e4 LT |
124 | |
125 | /* set last entry flag in current SBALE of current SBAL */ | |
564e1c86 | 126 | sbale = zfcp_qdio_sbale_curr(qdio, q_req); |
3ec90878 | 127 | sbale->eflags |= SBAL_EFLAGS_LAST_ENTRY; |
1da177e4 LT |
128 | |
129 | /* don't exceed last allowed SBAL */ | |
42428f74 | 130 | if (q_req->sbal_last == q_req->sbal_limit) |
1da177e4 LT |
131 | return NULL; |
132 | ||
133 | /* set chaining flag in first SBALE of current SBAL */ | |
564e1c86 | 134 | sbale = zfcp_qdio_sbale_req(qdio, q_req); |
3ec90878 | 135 | sbale->sflags |= SBAL_SFLAGS0_MORE_SBALS; |
1da177e4 LT |
136 | |
137 | /* calculate index of next SBAL */ | |
42428f74 SS |
138 | q_req->sbal_last++; |
139 | q_req->sbal_last %= QDIO_MAX_BUFFERS_PER_Q; | |
1da177e4 LT |
140 | |
141 | /* keep this requests number of SBALs up-to-date */ | |
42428f74 | 142 | q_req->sbal_number++; |
01b04759 | 143 | BUG_ON(q_req->sbal_number > ZFCP_QDIO_MAX_SBALS_PER_REQ); |
1da177e4 LT |
144 | |
145 | /* start at first SBALE of new SBAL */ | |
42428f74 | 146 | q_req->sbale_curr = 0; |
1da177e4 LT |
147 | |
148 | /* set storage-block type for new SBAL */ | |
564e1c86 | 149 | sbale = zfcp_qdio_sbale_curr(qdio, q_req); |
3ec90878 | 150 | sbale->sflags |= q_req->sbtype; |
1da177e4 LT |
151 | |
152 | return sbale; | |
153 | } | |
154 | ||
44cc76f2 | 155 | static struct qdio_buffer_element * |
1674b405 | 156 | zfcp_qdio_sbale_next(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req) |
1da177e4 | 157 | { |
1674b405 CS |
158 | if (q_req->sbale_curr == ZFCP_QDIO_LAST_SBALE_PER_SBAL) |
159 | return zfcp_qdio_sbal_chain(qdio, q_req); | |
42428f74 | 160 | q_req->sbale_curr++; |
564e1c86 | 161 | return zfcp_qdio_sbale_curr(qdio, q_req); |
1da177e4 LT |
162 | } |
163 | ||
1da177e4 LT |
164 | /** |
165 | * zfcp_qdio_sbals_from_sg - fill SBALs from scatter-gather list | |
1674b405 CS |
166 | * @qdio: pointer to struct zfcp_qdio |
167 | * @q_req: pointer to struct zfcp_qdio_req | |
1da177e4 | 168 | * @sg: scatter-gather list |
1da177e4 | 169 | * @max_sbals: upper bound for number of SBALs to be used |
00bab910 | 170 | * Returns: number of bytes, or error (negativ) |
1da177e4 | 171 | */ |
34c2b712 | 172 | int zfcp_qdio_sbals_from_sg(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req, |
01b04759 | 173 | struct scatterlist *sg) |
1da177e4 | 174 | { |
44cc76f2 | 175 | struct qdio_buffer_element *sbale; |
68322984 | 176 | int bytes = 0; |
1da177e4 | 177 | |
00bab910 | 178 | /* set storage-block type for this request */ |
564e1c86 | 179 | sbale = zfcp_qdio_sbale_req(qdio, q_req); |
3ec90878 | 180 | sbale->sflags |= q_req->sbtype; |
1da177e4 | 181 | |
00bab910 | 182 | for (; sg; sg = sg_next(sg)) { |
1674b405 | 183 | sbale = zfcp_qdio_sbale_next(qdio, q_req); |
68322984 CS |
184 | if (!sbale) { |
185 | atomic_inc(&qdio->req_q_full); | |
706eca49 SS |
186 | zfcp_qdio_zero_sbals(qdio->req_q, q_req->sbal_first, |
187 | q_req->sbal_number); | |
68322984 CS |
188 | return -EINVAL; |
189 | } | |
190 | ||
191 | sbale->addr = sg_virt(sg); | |
192 | sbale->length = sg->length; | |
193 | ||
00bab910 | 194 | bytes += sg->length; |
1da177e4 | 195 | } |
00bab910 | 196 | |
1da177e4 LT |
197 | return bytes; |
198 | } | |
199 | ||
6b9e1520 CS |
200 | static int zfcp_qdio_sbal_check(struct zfcp_qdio *qdio) |
201 | { | |
44a24cb3 | 202 | spin_lock_irq(&qdio->req_q_lock); |
706eca49 | 203 | if (atomic_read(&qdio->req_q_free) || |
c2af7545 | 204 | !(atomic_read(&qdio->adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) |
6b9e1520 | 205 | return 1; |
44a24cb3 | 206 | spin_unlock_irq(&qdio->req_q_lock); |
6b9e1520 CS |
207 | return 0; |
208 | } | |
209 | ||
210 | /** | |
211 | * zfcp_qdio_sbal_get - get free sbal in request queue, wait if necessary | |
212 | * @qdio: pointer to struct zfcp_qdio | |
213 | * | |
214 | * The req_q_lock must be held by the caller of this function, and | |
215 | * this function may only be called from process context; it will | |
216 | * sleep when waiting for a free sbal. | |
217 | * | |
218 | * Returns: 0 on success, -EIO if there is no free sbal after waiting. | |
219 | */ | |
220 | int zfcp_qdio_sbal_get(struct zfcp_qdio *qdio) | |
221 | { | |
222 | long ret; | |
223 | ||
44a24cb3 | 224 | spin_unlock_irq(&qdio->req_q_lock); |
6b9e1520 CS |
225 | ret = wait_event_interruptible_timeout(qdio->req_q_wq, |
226 | zfcp_qdio_sbal_check(qdio), 5 * HZ); | |
c2af7545 CS |
227 | |
228 | if (!(atomic_read(&qdio->adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) | |
229 | return -EIO; | |
230 | ||
6b9e1520 CS |
231 | if (ret > 0) |
232 | return 0; | |
c2af7545 | 233 | |
6b9e1520 CS |
234 | if (!ret) { |
235 | atomic_inc(&qdio->req_q_full); | |
236 | /* assume hanging outbound queue, try queue recovery */ | |
ea4a3a6a | 237 | zfcp_erp_adapter_reopen(qdio->adapter, 0, "qdsbg_1"); |
6b9e1520 CS |
238 | } |
239 | ||
44a24cb3 | 240 | spin_lock_irq(&qdio->req_q_lock); |
6b9e1520 CS |
241 | return -EIO; |
242 | } | |
243 | ||
1da177e4 | 244 | /** |
00bab910 | 245 | * zfcp_qdio_send - set PCI flag in first SBALE and send req to QDIO |
564e1c86 | 246 | * @qdio: pointer to struct zfcp_qdio |
34c2b712 | 247 | * @q_req: pointer to struct zfcp_qdio_req |
00bab910 | 248 | * Returns: 0 on success, error otherwise |
1da177e4 | 249 | */ |
34c2b712 | 250 | int zfcp_qdio_send(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req) |
1da177e4 | 251 | { |
21ddaa53 | 252 | int retval; |
706eca49 | 253 | u8 sbal_number = q_req->sbal_number; |
00bab910 | 254 | |
44a24cb3 | 255 | spin_lock(&qdio->stat_lock); |
564e1c86 | 256 | zfcp_qdio_account(qdio); |
44a24cb3 | 257 | spin_unlock(&qdio->stat_lock); |
94506fd1 | 258 | |
706eca49 SS |
259 | retval = do_QDIO(qdio->adapter->ccw_device, QDIO_FLAG_SYNC_OUTPUT, 0, |
260 | q_req->sbal_first, sbal_number); | |
261 | ||
00bab910 | 262 | if (unlikely(retval)) { |
706eca49 SS |
263 | zfcp_qdio_zero_sbals(qdio->req_q, q_req->sbal_first, |
264 | sbal_number); | |
00bab910 SS |
265 | return retval; |
266 | } | |
267 | ||
268 | /* account for transferred buffers */ | |
706eca49 SS |
269 | atomic_sub(sbal_number, &qdio->req_q_free); |
270 | qdio->req_q_idx += sbal_number; | |
271 | qdio->req_q_idx %= QDIO_MAX_BUFFERS_PER_Q; | |
272 | ||
00bab910 | 273 | return 0; |
1da177e4 LT |
274 | } |
275 | ||
564e1c86 SS |
276 | |
277 | static void zfcp_qdio_setup_init_data(struct qdio_initialize *id, | |
278 | struct zfcp_qdio *qdio) | |
279 | { | |
d36deae7 | 280 | memset(id, 0, sizeof(*id)); |
564e1c86 SS |
281 | id->cdev = qdio->adapter->ccw_device; |
282 | id->q_format = QDIO_ZFCP_QFMT; | |
283 | memcpy(id->adapter_name, dev_name(&id->cdev->dev), 8); | |
284 | ASCEBC(id->adapter_name, 8); | |
dcc18f48 | 285 | id->qib_rflags = QIB_RFLAGS_ENABLE_DATA_DIV; |
564e1c86 SS |
286 | id->no_input_qs = 1; |
287 | id->no_output_qs = 1; | |
288 | id->input_handler = zfcp_qdio_int_resp; | |
289 | id->output_handler = zfcp_qdio_int_req; | |
290 | id->int_parm = (unsigned long) qdio; | |
706eca49 SS |
291 | id->input_sbal_addr_array = (void **) (qdio->res_q); |
292 | id->output_sbal_addr_array = (void **) (qdio->req_q); | |
3d6c76ff JG |
293 | id->scan_threshold = |
294 | QDIO_MAX_BUFFERS_PER_Q - ZFCP_QDIO_MAX_SBALS_PER_REQ * 2; | |
564e1c86 | 295 | } |
dcc18f48 | 296 | |
00bab910 SS |
297 | /** |
298 | * zfcp_qdio_allocate - allocate queue memory and initialize QDIO data | |
299 | * @adapter: pointer to struct zfcp_adapter | |
300 | * Returns: -ENOMEM on memory allocation error or return value from | |
301 | * qdio_allocate | |
302 | */ | |
d5a282a1 | 303 | static int zfcp_qdio_allocate(struct zfcp_qdio *qdio) |
00bab910 | 304 | { |
564e1c86 | 305 | struct qdio_initialize init_data; |
00bab910 | 306 | |
706eca49 SS |
307 | if (zfcp_qdio_buffers_enqueue(qdio->req_q) || |
308 | zfcp_qdio_buffers_enqueue(qdio->res_q)) | |
00bab910 SS |
309 | return -ENOMEM; |
310 | ||
564e1c86 | 311 | zfcp_qdio_setup_init_data(&init_data, qdio); |
3d63d3b4 | 312 | init_waitqueue_head(&qdio->req_q_wq); |
564e1c86 SS |
313 | |
314 | return qdio_allocate(&init_data); | |
00bab910 SS |
315 | } |
316 | ||
317 | /** | |
318 | * zfcp_close_qdio - close qdio queues for an adapter | |
564e1c86 | 319 | * @qdio: pointer to structure zfcp_qdio |
1da177e4 | 320 | */ |
564e1c86 | 321 | void zfcp_qdio_close(struct zfcp_qdio *qdio) |
1da177e4 | 322 | { |
706eca49 SS |
323 | struct zfcp_adapter *adapter = qdio->adapter; |
324 | int idx, count; | |
00bab910 | 325 | |
706eca49 | 326 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) |
00bab910 SS |
327 | return; |
328 | ||
329 | /* clear QDIOUP flag, thus do_QDIO is not called during qdio_shutdown */ | |
44a24cb3 | 330 | spin_lock_irq(&qdio->req_q_lock); |
706eca49 | 331 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status); |
44a24cb3 | 332 | spin_unlock_irq(&qdio->req_q_lock); |
00bab910 | 333 | |
c2af7545 CS |
334 | wake_up(&qdio->req_q_wq); |
335 | ||
706eca49 | 336 | qdio_shutdown(adapter->ccw_device, QDIO_FLAG_CLEANUP_USING_CLEAR); |
00bab910 SS |
337 | |
338 | /* cleanup used outbound sbals */ | |
706eca49 | 339 | count = atomic_read(&qdio->req_q_free); |
00bab910 | 340 | if (count < QDIO_MAX_BUFFERS_PER_Q) { |
706eca49 | 341 | idx = (qdio->req_q_idx + count) % QDIO_MAX_BUFFERS_PER_Q; |
00bab910 | 342 | count = QDIO_MAX_BUFFERS_PER_Q - count; |
706eca49 | 343 | zfcp_qdio_zero_sbals(qdio->req_q, idx, count); |
1da177e4 | 344 | } |
706eca49 SS |
345 | qdio->req_q_idx = 0; |
346 | atomic_set(&qdio->req_q_free, 0); | |
1da177e4 LT |
347 | } |
348 | ||
00bab910 SS |
349 | /** |
350 | * zfcp_qdio_open - prepare and initialize response queue | |
564e1c86 | 351 | * @qdio: pointer to struct zfcp_qdio |
00bab910 SS |
352 | * Returns: 0 on success, otherwise -EIO |
353 | */ | |
564e1c86 | 354 | int zfcp_qdio_open(struct zfcp_qdio *qdio) |
00bab910 | 355 | { |
44cc76f2 | 356 | struct qdio_buffer_element *sbale; |
564e1c86 | 357 | struct qdio_initialize init_data; |
706eca49 SS |
358 | struct zfcp_adapter *adapter = qdio->adapter; |
359 | struct ccw_device *cdev = adapter->ccw_device; | |
dcc18f48 | 360 | struct qdio_ssqd_desc ssqd; |
00bab910 SS |
361 | int cc; |
362 | ||
706eca49 | 363 | if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP) |
00bab910 SS |
364 | return -EIO; |
365 | ||
339f4f4e CS |
366 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_SIOSL_ISSUED, |
367 | &qdio->adapter->status); | |
368 | ||
564e1c86 SS |
369 | zfcp_qdio_setup_init_data(&init_data, qdio); |
370 | ||
371 | if (qdio_establish(&init_data)) | |
ff3b24fa | 372 | goto failed_establish; |
00bab910 | 373 | |
dcc18f48 CS |
374 | if (qdio_get_ssqd_desc(init_data.cdev, &ssqd)) |
375 | goto failed_qdio; | |
376 | ||
377 | if (ssqd.qdioac2 & CHSC_AC2_DATA_DIV_ENABLED) | |
378 | atomic_set_mask(ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED, | |
379 | &qdio->adapter->status); | |
380 | ||
564e1c86 | 381 | if (qdio_activate(cdev)) |
00bab910 | 382 | goto failed_qdio; |
00bab910 SS |
383 | |
384 | for (cc = 0; cc < QDIO_MAX_BUFFERS_PER_Q; cc++) { | |
706eca49 | 385 | sbale = &(qdio->res_q[cc]->element[0]); |
00bab910 | 386 | sbale->length = 0; |
3ec90878 JG |
387 | sbale->eflags = SBAL_EFLAGS_LAST_ENTRY; |
388 | sbale->sflags = 0; | |
00bab910 SS |
389 | sbale->addr = NULL; |
390 | } | |
391 | ||
706eca49 | 392 | if (do_QDIO(cdev, QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q)) |
00bab910 | 393 | goto failed_qdio; |
00bab910 | 394 | |
25985edc | 395 | /* set index of first available SBALS / number of available SBALS */ |
706eca49 SS |
396 | qdio->req_q_idx = 0; |
397 | atomic_set(&qdio->req_q_free, QDIO_MAX_BUFFERS_PER_Q); | |
3d63d3b4 | 398 | atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &qdio->adapter->status); |
00bab910 SS |
399 | |
400 | return 0; | |
401 | ||
402 | failed_qdio: | |
564e1c86 | 403 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); |
ff3b24fa | 404 | failed_establish: |
564e1c86 | 405 | dev_err(&cdev->dev, |
ff3b24fa | 406 | "Setting up the QDIO connection to the FCP adapter failed\n"); |
00bab910 SS |
407 | return -EIO; |
408 | } | |
d5a282a1 SS |
409 | |
410 | void zfcp_qdio_destroy(struct zfcp_qdio *qdio) | |
411 | { | |
d5a282a1 SS |
412 | int p; |
413 | ||
414 | if (!qdio) | |
415 | return; | |
416 | ||
417 | if (qdio->adapter->ccw_device) | |
418 | qdio_free(qdio->adapter->ccw_device); | |
419 | ||
d5a282a1 | 420 | for (p = 0; p < QDIO_MAX_BUFFERS_PER_Q; p += QBUFF_PER_PAGE) { |
706eca49 SS |
421 | free_page((unsigned long) qdio->req_q[p]); |
422 | free_page((unsigned long) qdio->res_q[p]); | |
d5a282a1 SS |
423 | } |
424 | ||
425 | kfree(qdio); | |
426 | } | |
427 | ||
428 | int zfcp_qdio_setup(struct zfcp_adapter *adapter) | |
429 | { | |
430 | struct zfcp_qdio *qdio; | |
431 | ||
432 | qdio = kzalloc(sizeof(struct zfcp_qdio), GFP_KERNEL); | |
433 | if (!qdio) | |
434 | return -ENOMEM; | |
435 | ||
436 | qdio->adapter = adapter; | |
437 | ||
438 | if (zfcp_qdio_allocate(qdio)) { | |
439 | zfcp_qdio_destroy(qdio); | |
440 | return -ENOMEM; | |
441 | } | |
442 | ||
443 | spin_lock_init(&qdio->req_q_lock); | |
444 | spin_lock_init(&qdio->stat_lock); | |
445 | ||
446 | adapter->qdio = qdio; | |
447 | return 0; | |
448 | } | |
449 | ||
339f4f4e CS |
450 | /** |
451 | * zfcp_qdio_siosl - Trigger logging in FCP channel | |
452 | * @adapter: The zfcp_adapter where to trigger logging | |
453 | * | |
454 | * Call the cio siosl function to trigger hardware logging. This | |
455 | * wrapper function sets a flag to ensure hardware logging is only | |
456 | * triggered once before going through qdio shutdown. | |
457 | * | |
458 | * The triggers are always run from qdio tasklet context, so no | |
459 | * additional synchronization is necessary. | |
460 | */ | |
461 | void zfcp_qdio_siosl(struct zfcp_adapter *adapter) | |
462 | { | |
463 | int rc; | |
464 | ||
465 | if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_SIOSL_ISSUED) | |
466 | return; | |
467 | ||
468 | rc = ccw_device_siosl(adapter->ccw_device); | |
469 | if (!rc) | |
470 | atomic_set_mask(ZFCP_STATUS_ADAPTER_SIOSL_ISSUED, | |
471 | &adapter->status); | |
472 | } |