1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Linux for s390 qdio support, buffer handling, qdio API and module support.
4 *
5 * Copyright IBM Corp. 2000, 2008
6 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
7 * Jan Glauber <jang@linux.vnet.ibm.com>
8 * 2.6 cio integration by Cornelia Huck <cornelia.huck@de.ibm.com>
9 */
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/timer.h>
14 #include <linux/delay.h>
15 #include <linux/gfp.h>
16 #include <linux/io.h>
17 #include <linux/atomic.h>
18 #include <asm/debug.h>
19 #include <asm/qdio.h>
20 #include <asm/ipl.h>
21
22 #include "cio.h"
23 #include "css.h"
24 #include "device.h"
25 #include "qdio.h"
26 #include "qdio_debug.h"
27
28 MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>,"\
29 "Jan Glauber <jang@linux.vnet.ibm.com>");
30 MODULE_DESCRIPTION("QDIO base support");
31 MODULE_LICENSE("GPL");
32
do_siga_sync(unsigned long schid,unsigned long out_mask,unsigned long in_mask,unsigned int fc)33 static inline int do_siga_sync(unsigned long schid,
34 unsigned long out_mask, unsigned long in_mask,
35 unsigned int fc)
36 {
37 int cc;
38
39 asm volatile(
40 " lgr 0,%[fc]\n"
41 " lgr 1,%[schid]\n"
42 " lgr 2,%[out]\n"
43 " lgr 3,%[in]\n"
44 " siga 0\n"
45 " ipm %[cc]\n"
46 " srl %[cc],28\n"
47 : [cc] "=&d" (cc)
48 : [fc] "d" (fc), [schid] "d" (schid),
49 [out] "d" (out_mask), [in] "d" (in_mask)
50 : "cc", "0", "1", "2", "3");
51 return cc;
52 }
53
do_siga_input(unsigned long schid,unsigned long mask,unsigned long fc)54 static inline int do_siga_input(unsigned long schid, unsigned long mask,
55 unsigned long fc)
56 {
57 int cc;
58
59 asm volatile(
60 " lgr 0,%[fc]\n"
61 " lgr 1,%[schid]\n"
62 " lgr 2,%[mask]\n"
63 " siga 0\n"
64 " ipm %[cc]\n"
65 " srl %[cc],28\n"
66 : [cc] "=&d" (cc)
67 : [fc] "d" (fc), [schid] "d" (schid), [mask] "d" (mask)
68 : "cc", "0", "1", "2");
69 return cc;
70 }
71
72 /**
73 * do_siga_output - perform SIGA-w/wt function
74 * @schid: subchannel id or in case of QEBSM the subchannel token
75 * @mask: which output queues to process
76 * @bb: busy bit indicator, set only if SIGA-w/wt could not access a buffer
77 * @fc: function code to perform
78 * @aob: asynchronous operation block
79 *
80 * Returns condition code.
81 * Note: For IQDC unicast queues only the highest priority queue is processed.
82 */
do_siga_output(unsigned long schid,unsigned long mask,unsigned int * bb,unsigned long fc,unsigned long aob)83 static inline int do_siga_output(unsigned long schid, unsigned long mask,
84 unsigned int *bb, unsigned long fc,
85 unsigned long aob)
86 {
87 int cc;
88
89 asm volatile(
90 " lgr 0,%[fc]\n"
91 " lgr 1,%[schid]\n"
92 " lgr 2,%[mask]\n"
93 " lgr 3,%[aob]\n"
94 " siga 0\n"
95 " lgr %[fc],0\n"
96 " ipm %[cc]\n"
97 " srl %[cc],28\n"
98 : [cc] "=&d" (cc), [fc] "+&d" (fc)
99 : [schid] "d" (schid), [mask] "d" (mask), [aob] "d" (aob)
100 : "cc", "0", "1", "2", "3");
101 *bb = fc >> 31;
102 return cc;
103 }
104
105 /**
106 * qdio_do_eqbs - extract buffer states for QEBSM
107 * @q: queue to manipulate
108 * @state: state of the extracted buffers
109 * @start: buffer number to start at
110 * @count: count of buffers to examine
111 * @auto_ack: automatically acknowledge buffers
112 *
113 * Returns the number of successfully extracted equal buffer states.
114 * Stops processing if a state is different from the last buffers state.
115 */
qdio_do_eqbs(struct qdio_q * q,unsigned char * state,int start,int count,int auto_ack)116 static int qdio_do_eqbs(struct qdio_q *q, unsigned char *state,
117 int start, int count, int auto_ack)
118 {
119 int tmp_count = count, tmp_start = start, nr = q->nr;
120 unsigned int ccq = 0;
121
122 qperf_inc(q, eqbs);
123
124 if (!q->is_input_q)
125 nr += q->irq_ptr->nr_input_qs;
126 again:
127 ccq = do_eqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count,
128 auto_ack);
129
130 switch (ccq) {
131 case 0:
132 case 32:
133 /* all done, or next buffer state different */
134 return count - tmp_count;
135 case 96:
136 /* not all buffers processed */
137 qperf_inc(q, eqbs_partial);
138 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "EQBS part:%02x",
139 tmp_count);
140 return count - tmp_count;
141 case 97:
142 /* no buffer processed */
143 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "EQBS again:%2d", ccq);
144 goto again;
145 default:
146 DBF_ERROR("%4x ccq:%3d", SCH_NO(q), ccq);
147 DBF_ERROR("%4x EQBS ERROR", SCH_NO(q));
148 DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
149 q->handler(q->irq_ptr->cdev, QDIO_ERROR_GET_BUF_STATE, q->nr,
150 q->first_to_kick, count, q->irq_ptr->int_parm);
151 return 0;
152 }
153 }
154
155 /**
156 * qdio_do_sqbs - set buffer states for QEBSM
157 * @q: queue to manipulate
158 * @state: new state of the buffers
159 * @start: first buffer number to change
160 * @count: how many buffers to change
161 *
162 * Returns the number of successfully changed buffers.
163 * Does retrying until the specified count of buffer states is set or an
164 * error occurs.
165 */
qdio_do_sqbs(struct qdio_q * q,unsigned char state,int start,int count)166 static int qdio_do_sqbs(struct qdio_q *q, unsigned char state, int start,
167 int count)
168 {
169 unsigned int ccq = 0;
170 int tmp_count = count, tmp_start = start;
171 int nr = q->nr;
172
173 if (!count)
174 return 0;
175 qperf_inc(q, sqbs);
176
177 if (!q->is_input_q)
178 nr += q->irq_ptr->nr_input_qs;
179 again:
180 ccq = do_sqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count);
181
182 switch (ccq) {
183 case 0:
184 case 32:
185 /* all done, or active buffer adapter-owned */
186 WARN_ON_ONCE(tmp_count);
187 return count - tmp_count;
188 case 96:
189 /* not all buffers processed */
190 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "SQBS again:%2d", ccq);
191 qperf_inc(q, sqbs_partial);
192 goto again;
193 default:
194 DBF_ERROR("%4x ccq:%3d", SCH_NO(q), ccq);
195 DBF_ERROR("%4x SQBS ERROR", SCH_NO(q));
196 DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
197 q->handler(q->irq_ptr->cdev, QDIO_ERROR_SET_BUF_STATE, q->nr,
198 q->first_to_kick, count, q->irq_ptr->int_parm);
199 return 0;
200 }
201 }
202
203 /*
204 * Returns number of examined buffers and their common state in *state.
205 * Requested number of buffers-to-examine must be > 0.
206 */
get_buf_states(struct qdio_q * q,unsigned int bufnr,unsigned char * state,unsigned int count,int auto_ack,int merge_pending)207 static inline int get_buf_states(struct qdio_q *q, unsigned int bufnr,
208 unsigned char *state, unsigned int count,
209 int auto_ack, int merge_pending)
210 {
211 unsigned char __state = 0;
212 int i = 1;
213
214 if (is_qebsm(q))
215 return qdio_do_eqbs(q, state, bufnr, count, auto_ack);
216
217 /* get initial state: */
218 __state = q->slsb.val[bufnr];
219
220 /* Bail out early if there is no work on the queue: */
221 if (__state & SLSB_OWNER_CU)
222 goto out;
223
224 if (merge_pending && __state == SLSB_P_OUTPUT_PENDING)
225 __state = SLSB_P_OUTPUT_EMPTY;
226
227 for (; i < count; i++) {
228 bufnr = next_buf(bufnr);
229
230 /* merge PENDING into EMPTY: */
231 if (merge_pending &&
232 q->slsb.val[bufnr] == SLSB_P_OUTPUT_PENDING &&
233 __state == SLSB_P_OUTPUT_EMPTY)
234 continue;
235
236 /* stop if next state differs from initial state: */
237 if (q->slsb.val[bufnr] != __state)
238 break;
239 }
240
241 out:
242 *state = __state;
243 return i;
244 }
245
get_buf_state(struct qdio_q * q,unsigned int bufnr,unsigned char * state,int auto_ack)246 static inline int get_buf_state(struct qdio_q *q, unsigned int bufnr,
247 unsigned char *state, int auto_ack)
248 {
249 return get_buf_states(q, bufnr, state, 1, auto_ack, 0);
250 }
251
252 /* wrap-around safe setting of slsb states, returns number of changed buffers */
set_buf_states(struct qdio_q * q,int bufnr,unsigned char state,int count)253 static inline int set_buf_states(struct qdio_q *q, int bufnr,
254 unsigned char state, int count)
255 {
256 int i;
257
258 if (is_qebsm(q))
259 return qdio_do_sqbs(q, state, bufnr, count);
260
261 for (i = 0; i < count; i++) {
262 xchg(&q->slsb.val[bufnr], state);
263 bufnr = next_buf(bufnr);
264 }
265 return count;
266 }
267
set_buf_state(struct qdio_q * q,int bufnr,unsigned char state)268 static inline int set_buf_state(struct qdio_q *q, int bufnr,
269 unsigned char state)
270 {
271 return set_buf_states(q, bufnr, state, 1);
272 }
273
274 /* set slsb states to initial state */
qdio_init_buf_states(struct qdio_irq * irq_ptr)275 static void qdio_init_buf_states(struct qdio_irq *irq_ptr)
276 {
277 struct qdio_q *q;
278 int i;
279
280 for_each_input_queue(irq_ptr, q, i)
281 set_buf_states(q, 0, SLSB_P_INPUT_NOT_INIT,
282 QDIO_MAX_BUFFERS_PER_Q);
283 for_each_output_queue(irq_ptr, q, i)
284 set_buf_states(q, 0, SLSB_P_OUTPUT_NOT_INIT,
285 QDIO_MAX_BUFFERS_PER_Q);
286 }
287
qdio_siga_sync(struct qdio_q * q,unsigned int output,unsigned int input)288 static inline int qdio_siga_sync(struct qdio_q *q, unsigned int output,
289 unsigned int input)
290 {
291 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
292 unsigned int fc = QDIO_SIGA_SYNC;
293 int cc;
294
295 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-s:%1d", q->nr);
296 qperf_inc(q, siga_sync);
297
298 if (is_qebsm(q)) {
299 schid = q->irq_ptr->sch_token;
300 fc |= QDIO_SIGA_QEBSM_FLAG;
301 }
302
303 cc = do_siga_sync(schid, output, input, fc);
304 if (unlikely(cc))
305 DBF_ERROR("%4x SIGA-S:%2d", SCH_NO(q), cc);
306 return (cc) ? -EIO : 0;
307 }
308
qdio_siga_sync_q(struct qdio_q * q)309 static inline int qdio_siga_sync_q(struct qdio_q *q)
310 {
311 if (q->is_input_q)
312 return qdio_siga_sync(q, 0, q->mask);
313 else
314 return qdio_siga_sync(q, q->mask, 0);
315 }
316
qdio_siga_output(struct qdio_q * q,unsigned int * busy_bit,unsigned long aob)317 static int qdio_siga_output(struct qdio_q *q, unsigned int *busy_bit,
318 unsigned long aob)
319 {
320 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
321 unsigned int fc = QDIO_SIGA_WRITE;
322 u64 start_time = 0;
323 int retries = 0, cc;
324 unsigned long laob = 0;
325
326 if (aob) {
327 fc = QDIO_SIGA_WRITEQ;
328 laob = aob;
329 }
330
331 if (is_qebsm(q)) {
332 schid = q->irq_ptr->sch_token;
333 fc |= QDIO_SIGA_QEBSM_FLAG;
334 }
335 again:
336 cc = do_siga_output(schid, q->mask, busy_bit, fc, laob);
337
338 /* hipersocket busy condition */
339 if (unlikely(*busy_bit)) {
340 retries++;
341
342 if (!start_time) {
343 start_time = get_tod_clock_fast();
344 goto again;
345 }
346 if (get_tod_clock_fast() - start_time < QDIO_BUSY_BIT_PATIENCE)
347 goto again;
348 }
349 if (retries) {
350 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr,
351 "%4x cc2 BB1:%1d", SCH_NO(q), q->nr);
352 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "count:%u", retries);
353 }
354 return cc;
355 }
356
qdio_siga_input(struct qdio_q * q)357 static inline int qdio_siga_input(struct qdio_q *q)
358 {
359 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
360 unsigned int fc = QDIO_SIGA_READ;
361 int cc;
362
363 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-r:%1d", q->nr);
364 qperf_inc(q, siga_read);
365
366 if (is_qebsm(q)) {
367 schid = q->irq_ptr->sch_token;
368 fc |= QDIO_SIGA_QEBSM_FLAG;
369 }
370
371 cc = do_siga_input(schid, q->mask, fc);
372 if (unlikely(cc))
373 DBF_ERROR("%4x SIGA-R:%2d", SCH_NO(q), cc);
374 return (cc) ? -EIO : 0;
375 }
376
377 #define qdio_siga_sync_out(q) qdio_siga_sync(q, ~0U, 0)
378 #define qdio_siga_sync_all(q) qdio_siga_sync(q, ~0U, ~0U)
379
qdio_sync_queues(struct qdio_q * q)380 static inline void qdio_sync_queues(struct qdio_q *q)
381 {
382 /* PCI capable outbound queues will also be scanned so sync them too */
383 if (pci_out_supported(q->irq_ptr))
384 qdio_siga_sync_all(q);
385 else
386 qdio_siga_sync_q(q);
387 }
388
debug_get_buf_state(struct qdio_q * q,unsigned int bufnr,unsigned char * state)389 int debug_get_buf_state(struct qdio_q *q, unsigned int bufnr,
390 unsigned char *state)
391 {
392 if (need_siga_sync(q))
393 qdio_siga_sync_q(q);
394 return get_buf_state(q, bufnr, state, 0);
395 }
396
qdio_stop_polling(struct qdio_q * q)397 static inline void qdio_stop_polling(struct qdio_q *q)
398 {
399 if (!q->u.in.polling)
400 return;
401
402 q->u.in.polling = 0;
403 qperf_inc(q, stop_polling);
404
405 /* show the card that we are not polling anymore */
406 if (is_qebsm(q)) {
407 set_buf_states(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT,
408 q->u.in.ack_count);
409 q->u.in.ack_count = 0;
410 } else
411 set_buf_state(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT);
412 }
413
account_sbals(struct qdio_q * q,unsigned int count)414 static inline void account_sbals(struct qdio_q *q, unsigned int count)
415 {
416 int pos;
417
418 q->q_stats.nr_sbal_total += count;
419 if (count == QDIO_MAX_BUFFERS_MASK) {
420 q->q_stats.nr_sbals[7]++;
421 return;
422 }
423 pos = ilog2(count);
424 q->q_stats.nr_sbals[pos]++;
425 }
426
process_buffer_error(struct qdio_q * q,unsigned int start,int count)427 static void process_buffer_error(struct qdio_q *q, unsigned int start,
428 int count)
429 {
430 unsigned char state = (q->is_input_q) ? SLSB_P_INPUT_NOT_INIT :
431 SLSB_P_OUTPUT_NOT_INIT;
432
433 q->qdio_error = QDIO_ERROR_SLSB_STATE;
434
435 /* special handling for no target buffer empty */
436 if (queue_type(q) == QDIO_IQDIO_QFMT && !q->is_input_q &&
437 q->sbal[start]->element[15].sflags == 0x10) {
438 qperf_inc(q, target_full);
439 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "OUTFULL FTC:%02x", start);
440 goto set;
441 }
442
443 DBF_ERROR("%4x BUF ERROR", SCH_NO(q));
444 DBF_ERROR((q->is_input_q) ? "IN:%2d" : "OUT:%2d", q->nr);
445 DBF_ERROR("FTC:%3d C:%3d", start, count);
446 DBF_ERROR("F14:%2x F15:%2x",
447 q->sbal[start]->element[14].sflags,
448 q->sbal[start]->element[15].sflags);
449
450 set:
451 /*
452 * Interrupts may be avoided as long as the error is present
453 * so change the buffer state immediately to avoid starvation.
454 */
455 set_buf_states(q, start, state, count);
456 }
457
inbound_primed(struct qdio_q * q,unsigned int start,int count)458 static inline void inbound_primed(struct qdio_q *q, unsigned int start,
459 int count)
460 {
461 int new;
462
463 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in prim:%1d %02x", q->nr, count);
464
465 /* for QEBSM the ACK was already set by EQBS */
466 if (is_qebsm(q)) {
467 if (!q->u.in.polling) {
468 q->u.in.polling = 1;
469 q->u.in.ack_count = count;
470 q->u.in.ack_start = start;
471 return;
472 }
473
474 /* delete the previous ACK's */
475 set_buf_states(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT,
476 q->u.in.ack_count);
477 q->u.in.ack_count = count;
478 q->u.in.ack_start = start;
479 return;
480 }
481
482 /*
483 * ACK the newest buffer. The ACK will be removed in qdio_stop_polling
484 * or by the next inbound run.
485 */
486 new = add_buf(start, count - 1);
487 if (q->u.in.polling) {
488 /* reset the previous ACK but first set the new one */
489 set_buf_state(q, new, SLSB_P_INPUT_ACK);
490 set_buf_state(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT);
491 } else {
492 q->u.in.polling = 1;
493 set_buf_state(q, new, SLSB_P_INPUT_ACK);
494 }
495
496 q->u.in.ack_start = new;
497 count--;
498 if (!count)
499 return;
500 /* need to change ALL buffers to get more interrupts */
501 set_buf_states(q, start, SLSB_P_INPUT_NOT_INIT, count);
502 }
503
get_inbound_buffer_frontier(struct qdio_q * q,unsigned int start)504 static int get_inbound_buffer_frontier(struct qdio_q *q, unsigned int start)
505 {
506 unsigned char state = 0;
507 int count;
508
509 q->timestamp = get_tod_clock_fast();
510
511 /*
512 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
513 * would return 0.
514 */
515 count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
516 if (!count)
517 return 0;
518
519 /*
520 * No siga sync here, as a PCI or we after a thin interrupt
521 * already sync'ed the queues.
522 */
523 count = get_buf_states(q, start, &state, count, 1, 0);
524 if (!count)
525 return 0;
526
527 switch (state) {
528 case SLSB_P_INPUT_PRIMED:
529 inbound_primed(q, start, count);
530 if (atomic_sub_return(count, &q->nr_buf_used) == 0)
531 qperf_inc(q, inbound_queue_full);
532 if (q->irq_ptr->perf_stat_enabled)
533 account_sbals(q, count);
534 return count;
535 case SLSB_P_INPUT_ERROR:
536 process_buffer_error(q, start, count);
537 if (atomic_sub_return(count, &q->nr_buf_used) == 0)
538 qperf_inc(q, inbound_queue_full);
539 if (q->irq_ptr->perf_stat_enabled)
540 account_sbals_error(q, count);
541 return count;
542 case SLSB_CU_INPUT_EMPTY:
543 case SLSB_P_INPUT_NOT_INIT:
544 case SLSB_P_INPUT_ACK:
545 if (q->irq_ptr->perf_stat_enabled)
546 q->q_stats.nr_sbal_nop++;
547 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in nop:%1d %#02x",
548 q->nr, start);
549 return 0;
550 default:
551 WARN_ON_ONCE(1);
552 return 0;
553 }
554 }
555
qdio_inbound_q_moved(struct qdio_q * q,unsigned int start)556 static int qdio_inbound_q_moved(struct qdio_q *q, unsigned int start)
557 {
558 int count;
559
560 count = get_inbound_buffer_frontier(q, start);
561
562 if (count && !is_thinint_irq(q->irq_ptr) && MACHINE_IS_LPAR)
563 q->u.in.timestamp = get_tod_clock();
564
565 return count;
566 }
567
qdio_inbound_q_done(struct qdio_q * q,unsigned int start)568 static inline int qdio_inbound_q_done(struct qdio_q *q, unsigned int start)
569 {
570 unsigned char state = 0;
571
572 if (!atomic_read(&q->nr_buf_used))
573 return 1;
574
575 if (need_siga_sync(q))
576 qdio_siga_sync_q(q);
577 get_buf_state(q, start, &state, 0);
578
579 if (state == SLSB_P_INPUT_PRIMED || state == SLSB_P_INPUT_ERROR)
580 /* more work coming */
581 return 0;
582
583 if (is_thinint_irq(q->irq_ptr))
584 return 1;
585
586 /* don't poll under z/VM */
587 if (MACHINE_IS_VM)
588 return 1;
589
590 /*
591 * At this point we know, that inbound first_to_check
592 * has (probably) not moved (see qdio_inbound_processing).
593 */
594 if (get_tod_clock_fast() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) {
595 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in done:%02x", start);
596 return 1;
597 } else
598 return 0;
599 }
600
qdio_handle_aobs(struct qdio_q * q,int start,int count)601 static inline void qdio_handle_aobs(struct qdio_q *q, int start, int count)
602 {
603 unsigned char state = 0;
604 int j, b = start;
605
606 for (j = 0; j < count; ++j) {
607 get_buf_state(q, b, &state, 0);
608 if (state == SLSB_P_OUTPUT_PENDING) {
609 struct qaob *aob = q->u.out.aobs[b];
610 if (aob == NULL)
611 continue;
612
613 q->u.out.sbal_state[b].flags |=
614 QDIO_OUTBUF_STATE_FLAG_PENDING;
615 q->u.out.aobs[b] = NULL;
616 }
617 b = next_buf(b);
618 }
619 }
620
qdio_aob_for_buffer(struct qdio_output_q * q,int bufnr)621 static inline unsigned long qdio_aob_for_buffer(struct qdio_output_q *q,
622 int bufnr)
623 {
624 unsigned long phys_aob = 0;
625
626 if (!q->aobs[bufnr]) {
627 struct qaob *aob = qdio_allocate_aob();
628 q->aobs[bufnr] = aob;
629 }
630 if (q->aobs[bufnr]) {
631 q->aobs[bufnr]->user1 = (u64) q->sbal_state[bufnr].user;
632 phys_aob = virt_to_phys(q->aobs[bufnr]);
633 WARN_ON_ONCE(phys_aob & 0xFF);
634 }
635
636 q->sbal_state[bufnr].flags = 0;
637 return phys_aob;
638 }
639
qdio_kick_handler(struct qdio_q * q,unsigned int count)640 static void qdio_kick_handler(struct qdio_q *q, unsigned int count)
641 {
642 int start = q->first_to_kick;
643
644 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
645 return;
646
647 if (q->is_input_q) {
648 qperf_inc(q, inbound_handler);
649 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "kih s:%02x c:%02x", start, count);
650 } else {
651 qperf_inc(q, outbound_handler);
652 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "koh: s:%02x c:%02x",
653 start, count);
654 }
655
656 q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr, start, count,
657 q->irq_ptr->int_parm);
658
659 /* for the next time */
660 q->first_to_kick = add_buf(start, count);
661 q->qdio_error = 0;
662 }
663
qdio_tasklet_schedule(struct qdio_q * q)664 static inline int qdio_tasklet_schedule(struct qdio_q *q)
665 {
666 if (likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE)) {
667 tasklet_schedule(&q->tasklet);
668 return 0;
669 }
670 return -EPERM;
671 }
672
__qdio_inbound_processing(struct qdio_q * q)673 static void __qdio_inbound_processing(struct qdio_q *q)
674 {
675 unsigned int start = q->first_to_check;
676 int count;
677
678 qperf_inc(q, tasklet_inbound);
679
680 count = qdio_inbound_q_moved(q, start);
681 if (count == 0)
682 return;
683
684 start = add_buf(start, count);
685 q->first_to_check = start;
686 qdio_kick_handler(q, count);
687
688 if (!qdio_inbound_q_done(q, start)) {
689 /* means poll time is not yet over */
690 qperf_inc(q, tasklet_inbound_resched);
691 if (!qdio_tasklet_schedule(q))
692 return;
693 }
694
695 qdio_stop_polling(q);
696 /*
697 * We need to check again to not lose initiative after
698 * resetting the ACK state.
699 */
700 if (!qdio_inbound_q_done(q, start)) {
701 qperf_inc(q, tasklet_inbound_resched2);
702 qdio_tasklet_schedule(q);
703 }
704 }
705
qdio_inbound_processing(unsigned long data)706 void qdio_inbound_processing(unsigned long data)
707 {
708 struct qdio_q *q = (struct qdio_q *)data;
709 __qdio_inbound_processing(q);
710 }
711
get_outbound_buffer_frontier(struct qdio_q * q,unsigned int start)712 static int get_outbound_buffer_frontier(struct qdio_q *q, unsigned int start)
713 {
714 unsigned char state = 0;
715 int count;
716
717 q->timestamp = get_tod_clock_fast();
718
719 if (need_siga_sync(q))
720 if (((queue_type(q) != QDIO_IQDIO_QFMT) &&
721 !pci_out_supported(q->irq_ptr)) ||
722 (queue_type(q) == QDIO_IQDIO_QFMT &&
723 multicast_outbound(q)))
724 qdio_siga_sync_q(q);
725
726 count = atomic_read(&q->nr_buf_used);
727 if (!count)
728 return 0;
729
730 count = get_buf_states(q, start, &state, count, 0, q->u.out.use_cq);
731 if (!count)
732 return 0;
733
734 switch (state) {
735 case SLSB_P_OUTPUT_EMPTY:
736 case SLSB_P_OUTPUT_PENDING:
737 /* the adapter got it */
738 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr,
739 "out empty:%1d %02x", q->nr, count);
740
741 atomic_sub(count, &q->nr_buf_used);
742 if (q->irq_ptr->perf_stat_enabled)
743 account_sbals(q, count);
744 return count;
745 case SLSB_P_OUTPUT_ERROR:
746 process_buffer_error(q, start, count);
747 atomic_sub(count, &q->nr_buf_used);
748 if (q->irq_ptr->perf_stat_enabled)
749 account_sbals_error(q, count);
750 return count;
751 case SLSB_CU_OUTPUT_PRIMED:
752 /* the adapter has not fetched the output yet */
753 if (q->irq_ptr->perf_stat_enabled)
754 q->q_stats.nr_sbal_nop++;
755 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out primed:%1d",
756 q->nr);
757 return 0;
758 case SLSB_P_OUTPUT_NOT_INIT:
759 case SLSB_P_OUTPUT_HALTED:
760 return 0;
761 default:
762 WARN_ON_ONCE(1);
763 return 0;
764 }
765 }
766
767 /* all buffers processed? */
qdio_outbound_q_done(struct qdio_q * q)768 static inline int qdio_outbound_q_done(struct qdio_q *q)
769 {
770 return atomic_read(&q->nr_buf_used) == 0;
771 }
772
qdio_outbound_q_moved(struct qdio_q * q,unsigned int start)773 static inline int qdio_outbound_q_moved(struct qdio_q *q, unsigned int start)
774 {
775 int count;
776
777 count = get_outbound_buffer_frontier(q, start);
778
779 if (count) {
780 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out moved:%1d", q->nr);
781 if (q->u.out.use_cq)
782 qdio_handle_aobs(q, start, count);
783 }
784
785 return count;
786 }
787
qdio_kick_outbound_q(struct qdio_q * q,unsigned long aob)788 static int qdio_kick_outbound_q(struct qdio_q *q, unsigned long aob)
789 {
790 int retries = 0, cc;
791 unsigned int busy_bit;
792
793 if (!need_siga_out(q))
794 return 0;
795
796 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w:%1d", q->nr);
797 retry:
798 qperf_inc(q, siga_write);
799
800 cc = qdio_siga_output(q, &busy_bit, aob);
801 switch (cc) {
802 case 0:
803 break;
804 case 2:
805 if (busy_bit) {
806 while (++retries < QDIO_BUSY_BIT_RETRIES) {
807 mdelay(QDIO_BUSY_BIT_RETRY_DELAY);
808 goto retry;
809 }
810 DBF_ERROR("%4x cc2 BBC:%1d", SCH_NO(q), q->nr);
811 cc = -EBUSY;
812 } else {
813 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w cc2:%1d", q->nr);
814 cc = -ENOBUFS;
815 }
816 break;
817 case 1:
818 case 3:
819 DBF_ERROR("%4x SIGA-W:%1d", SCH_NO(q), cc);
820 cc = -EIO;
821 break;
822 }
823 if (retries) {
824 DBF_ERROR("%4x cc2 BB2:%1d", SCH_NO(q), q->nr);
825 DBF_ERROR("count:%u", retries);
826 }
827 return cc;
828 }
829
__qdio_outbound_processing(struct qdio_q * q)830 static void __qdio_outbound_processing(struct qdio_q *q)
831 {
832 unsigned int start = q->first_to_check;
833 int count;
834
835 qperf_inc(q, tasklet_outbound);
836 WARN_ON_ONCE(atomic_read(&q->nr_buf_used) < 0);
837
838 count = qdio_outbound_q_moved(q, start);
839 if (count) {
840 q->first_to_check = add_buf(start, count);
841 qdio_kick_handler(q, count);
842 }
843
844 if (queue_type(q) == QDIO_ZFCP_QFMT && !pci_out_supported(q->irq_ptr) &&
845 !qdio_outbound_q_done(q))
846 goto sched;
847
848 if (q->u.out.pci_out_enabled)
849 return;
850
851 /*
852 * Now we know that queue type is either qeth without pci enabled
853 * or HiperSockets. Make sure buffer switch from PRIMED to EMPTY
854 * is noticed and outbound_handler is called after some time.
855 */
856 if (qdio_outbound_q_done(q))
857 del_timer_sync(&q->u.out.timer);
858 else
859 if (!timer_pending(&q->u.out.timer) &&
860 likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE))
861 mod_timer(&q->u.out.timer, jiffies + 10 * HZ);
862 return;
863
864 sched:
865 qdio_tasklet_schedule(q);
866 }
867
868 /* outbound tasklet */
qdio_outbound_processing(unsigned long data)869 void qdio_outbound_processing(unsigned long data)
870 {
871 struct qdio_q *q = (struct qdio_q *)data;
872 __qdio_outbound_processing(q);
873 }
874
qdio_outbound_timer(struct timer_list * t)875 void qdio_outbound_timer(struct timer_list *t)
876 {
877 struct qdio_q *q = from_timer(q, t, u.out.timer);
878
879 qdio_tasklet_schedule(q);
880 }
881
qdio_check_outbound_pci_queues(struct qdio_irq * irq)882 static inline void qdio_check_outbound_pci_queues(struct qdio_irq *irq)
883 {
884 struct qdio_q *out;
885 int i;
886
887 if (!pci_out_supported(irq) || !irq->scan_threshold)
888 return;
889
890 for_each_output_queue(irq, out, i)
891 if (!qdio_outbound_q_done(out))
892 qdio_tasklet_schedule(out);
893 }
894
__tiqdio_inbound_processing(struct qdio_q * q)895 static void __tiqdio_inbound_processing(struct qdio_q *q)
896 {
897 unsigned int start = q->first_to_check;
898 int count;
899
900 qperf_inc(q, tasklet_inbound);
901 if (need_siga_sync(q) && need_siga_sync_after_ai(q))
902 qdio_sync_queues(q);
903
904 /* The interrupt could be caused by a PCI request: */
905 qdio_check_outbound_pci_queues(q->irq_ptr);
906
907 count = qdio_inbound_q_moved(q, start);
908 if (count == 0)
909 return;
910
911 start = add_buf(start, count);
912 q->first_to_check = start;
913 qdio_kick_handler(q, count);
914
915 if (!qdio_inbound_q_done(q, start)) {
916 qperf_inc(q, tasklet_inbound_resched);
917 if (!qdio_tasklet_schedule(q))
918 return;
919 }
920
921 qdio_stop_polling(q);
922 /*
923 * We need to check again to not lose initiative after
924 * resetting the ACK state.
925 */
926 if (!qdio_inbound_q_done(q, start)) {
927 qperf_inc(q, tasklet_inbound_resched2);
928 qdio_tasklet_schedule(q);
929 }
930 }
931
tiqdio_inbound_processing(unsigned long data)932 void tiqdio_inbound_processing(unsigned long data)
933 {
934 struct qdio_q *q = (struct qdio_q *)data;
935 __tiqdio_inbound_processing(q);
936 }
937
qdio_set_state(struct qdio_irq * irq_ptr,enum qdio_irq_states state)938 static inline void qdio_set_state(struct qdio_irq *irq_ptr,
939 enum qdio_irq_states state)
940 {
941 DBF_DEV_EVENT(DBF_INFO, irq_ptr, "newstate: %1d", state);
942
943 irq_ptr->state = state;
944 mb();
945 }
946
qdio_irq_check_sense(struct qdio_irq * irq_ptr,struct irb * irb)947 static void qdio_irq_check_sense(struct qdio_irq *irq_ptr, struct irb *irb)
948 {
949 if (irb->esw.esw0.erw.cons) {
950 DBF_ERROR("%4x sense:", irq_ptr->schid.sch_no);
951 DBF_ERROR_HEX(irb, 64);
952 DBF_ERROR_HEX(irb->ecw, 64);
953 }
954 }
955
956 /* PCI interrupt handler */
qdio_int_handler_pci(struct qdio_irq * irq_ptr)957 static void qdio_int_handler_pci(struct qdio_irq *irq_ptr)
958 {
959 int i;
960 struct qdio_q *q;
961
962 if (unlikely(irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
963 return;
964
965 for_each_input_queue(irq_ptr, q, i) {
966 if (q->u.in.queue_start_poll) {
967 /* skip if polling is enabled or already in work */
968 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
969 &q->u.in.queue_irq_state)) {
970 qperf_inc(q, int_discarded);
971 continue;
972 }
973 q->u.in.queue_start_poll(q->irq_ptr->cdev, q->nr,
974 q->irq_ptr->int_parm);
975 } else {
976 tasklet_schedule(&q->tasklet);
977 }
978 }
979
980 if (!pci_out_supported(irq_ptr) || !irq_ptr->scan_threshold)
981 return;
982
983 for_each_output_queue(irq_ptr, q, i) {
984 if (qdio_outbound_q_done(q))
985 continue;
986 if (need_siga_sync(q) && need_siga_sync_out_after_pci(q))
987 qdio_siga_sync_q(q);
988 qdio_tasklet_schedule(q);
989 }
990 }
991
qdio_handle_activate_check(struct ccw_device * cdev,unsigned long intparm,int cstat,int dstat)992 static void qdio_handle_activate_check(struct ccw_device *cdev,
993 unsigned long intparm, int cstat, int dstat)
994 {
995 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
996 struct qdio_q *q;
997 int count;
998
999 DBF_ERROR("%4x ACT CHECK", irq_ptr->schid.sch_no);
1000 DBF_ERROR("intp :%lx", intparm);
1001 DBF_ERROR("ds: %2x cs:%2x", dstat, cstat);
1002
1003 if (irq_ptr->nr_input_qs) {
1004 q = irq_ptr->input_qs[0];
1005 } else if (irq_ptr->nr_output_qs) {
1006 q = irq_ptr->output_qs[0];
1007 } else {
1008 dump_stack();
1009 goto no_handler;
1010 }
1011
1012 count = sub_buf(q->first_to_check, q->first_to_kick);
1013 q->handler(q->irq_ptr->cdev, QDIO_ERROR_ACTIVATE,
1014 q->nr, q->first_to_kick, count, irq_ptr->int_parm);
1015 no_handler:
1016 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
1017 /*
1018 * In case of z/VM LGR (Live Guest Migration) QDIO recovery will happen.
1019 * Therefore we call the LGR detection function here.
1020 */
1021 lgr_info_log();
1022 }
1023
qdio_establish_handle_irq(struct ccw_device * cdev,int cstat,int dstat)1024 static void qdio_establish_handle_irq(struct ccw_device *cdev, int cstat,
1025 int dstat)
1026 {
1027 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1028
1029 DBF_DEV_EVENT(DBF_INFO, irq_ptr, "qest irq");
1030
1031 if (cstat)
1032 goto error;
1033 if (dstat & ~(DEV_STAT_DEV_END | DEV_STAT_CHN_END))
1034 goto error;
1035 if (!(dstat & DEV_STAT_DEV_END))
1036 goto error;
1037 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ESTABLISHED);
1038 return;
1039
1040 error:
1041 DBF_ERROR("%4x EQ:error", irq_ptr->schid.sch_no);
1042 DBF_ERROR("ds: %2x cs:%2x", dstat, cstat);
1043 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
1044 }
1045
1046 /* qdio interrupt handler */
qdio_int_handler(struct ccw_device * cdev,unsigned long intparm,struct irb * irb)1047 void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
1048 struct irb *irb)
1049 {
1050 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1051 struct subchannel_id schid;
1052 int cstat, dstat;
1053
1054 if (!intparm || !irq_ptr) {
1055 ccw_device_get_schid(cdev, &schid);
1056 DBF_ERROR("qint:%4x", schid.sch_no);
1057 return;
1058 }
1059
1060 if (irq_ptr->perf_stat_enabled)
1061 irq_ptr->perf_stat.qdio_int++;
1062
1063 if (IS_ERR(irb)) {
1064 DBF_ERROR("%4x IO error", irq_ptr->schid.sch_no);
1065 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
1066 wake_up(&cdev->private->wait_q);
1067 return;
1068 }
1069 qdio_irq_check_sense(irq_ptr, irb);
1070 cstat = irb->scsw.cmd.cstat;
1071 dstat = irb->scsw.cmd.dstat;
1072
1073 switch (irq_ptr->state) {
1074 case QDIO_IRQ_STATE_INACTIVE:
1075 qdio_establish_handle_irq(cdev, cstat, dstat);
1076 break;
1077 case QDIO_IRQ_STATE_CLEANUP:
1078 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1079 break;
1080 case QDIO_IRQ_STATE_ESTABLISHED:
1081 case QDIO_IRQ_STATE_ACTIVE:
1082 if (cstat & SCHN_STAT_PCI) {
1083 qdio_int_handler_pci(irq_ptr);
1084 return;
1085 }
1086 if (cstat || dstat)
1087 qdio_handle_activate_check(cdev, intparm, cstat,
1088 dstat);
1089 break;
1090 case QDIO_IRQ_STATE_STOPPED:
1091 break;
1092 default:
1093 WARN_ON_ONCE(1);
1094 }
1095 wake_up(&cdev->private->wait_q);
1096 }
1097
1098 /**
1099 * qdio_get_ssqd_desc - get qdio subchannel description
1100 * @cdev: ccw device to get description for
1101 * @data: where to store the ssqd
1102 *
1103 * Returns 0 or an error code. The results of the chsc are stored in the
1104 * specified structure.
1105 */
qdio_get_ssqd_desc(struct ccw_device * cdev,struct qdio_ssqd_desc * data)1106 int qdio_get_ssqd_desc(struct ccw_device *cdev,
1107 struct qdio_ssqd_desc *data)
1108 {
1109 struct subchannel_id schid;
1110
1111 if (!cdev || !cdev->private)
1112 return -EINVAL;
1113
1114 ccw_device_get_schid(cdev, &schid);
1115 DBF_EVENT("get ssqd:%4x", schid.sch_no);
1116 return qdio_setup_get_ssqd(NULL, &schid, data);
1117 }
1118 EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc);
1119
qdio_shutdown_queues(struct ccw_device * cdev)1120 static void qdio_shutdown_queues(struct ccw_device *cdev)
1121 {
1122 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1123 struct qdio_q *q;
1124 int i;
1125
1126 for_each_input_queue(irq_ptr, q, i)
1127 tasklet_kill(&q->tasklet);
1128
1129 for_each_output_queue(irq_ptr, q, i) {
1130 del_timer_sync(&q->u.out.timer);
1131 tasklet_kill(&q->tasklet);
1132 }
1133 }
1134
1135 /**
1136 * qdio_shutdown - shut down a qdio subchannel
1137 * @cdev: associated ccw device
1138 * @how: use halt or clear to shutdown
1139 */
qdio_shutdown(struct ccw_device * cdev,int how)1140 int qdio_shutdown(struct ccw_device *cdev, int how)
1141 {
1142 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1143 struct subchannel_id schid;
1144 int rc;
1145
1146 if (!irq_ptr)
1147 return -ENODEV;
1148
1149 WARN_ON_ONCE(irqs_disabled());
1150 ccw_device_get_schid(cdev, &schid);
1151 DBF_EVENT("qshutdown:%4x", schid.sch_no);
1152
1153 mutex_lock(&irq_ptr->setup_mutex);
1154 /*
1155 * Subchannel was already shot down. We cannot prevent being called
1156 * twice since cio may trigger a shutdown asynchronously.
1157 */
1158 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1159 mutex_unlock(&irq_ptr->setup_mutex);
1160 return 0;
1161 }
1162
1163 /*
1164 * Indicate that the device is going down. Scheduling the queue
1165 * tasklets is forbidden from here on.
1166 */
1167 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
1168
1169 tiqdio_remove_input_queues(irq_ptr);
1170 qdio_shutdown_queues(cdev);
1171 qdio_shutdown_debug_entries(irq_ptr);
1172
1173 /* cleanup subchannel */
1174 spin_lock_irq(get_ccwdev_lock(cdev));
1175
1176 if (how & QDIO_FLAG_CLEANUP_USING_CLEAR)
1177 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
1178 else
1179 /* default behaviour is halt */
1180 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
1181 if (rc) {
1182 DBF_ERROR("%4x SHUTD ERR", irq_ptr->schid.sch_no);
1183 DBF_ERROR("rc:%4d", rc);
1184 goto no_cleanup;
1185 }
1186
1187 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
1188 spin_unlock_irq(get_ccwdev_lock(cdev));
1189 wait_event_interruptible_timeout(cdev->private->wait_q,
1190 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
1191 irq_ptr->state == QDIO_IRQ_STATE_ERR,
1192 10 * HZ);
1193 spin_lock_irq(get_ccwdev_lock(cdev));
1194
1195 no_cleanup:
1196 qdio_shutdown_thinint(irq_ptr);
1197
1198 /* restore interrupt handler */
1199 if ((void *)cdev->handler == (void *)qdio_int_handler) {
1200 cdev->handler = irq_ptr->orig_handler;
1201 cdev->private->intparm = 0;
1202 }
1203 spin_unlock_irq(get_ccwdev_lock(cdev));
1204
1205 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1206 mutex_unlock(&irq_ptr->setup_mutex);
1207 if (rc)
1208 return rc;
1209 return 0;
1210 }
1211 EXPORT_SYMBOL_GPL(qdio_shutdown);
1212
1213 /**
1214 * qdio_free - free data structures for a qdio subchannel
1215 * @cdev: associated ccw device
1216 */
qdio_free(struct ccw_device * cdev)1217 int qdio_free(struct ccw_device *cdev)
1218 {
1219 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1220 struct subchannel_id schid;
1221
1222 if (!irq_ptr)
1223 return -ENODEV;
1224
1225 ccw_device_get_schid(cdev, &schid);
1226 DBF_EVENT("qfree:%4x", schid.sch_no);
1227 DBF_DEV_EVENT(DBF_ERR, irq_ptr, "dbf abandoned");
1228 mutex_lock(&irq_ptr->setup_mutex);
1229
1230 irq_ptr->debug_area = NULL;
1231 cdev->private->qdio_data = NULL;
1232 mutex_unlock(&irq_ptr->setup_mutex);
1233
1234 qdio_release_memory(irq_ptr);
1235 return 0;
1236 }
1237 EXPORT_SYMBOL_GPL(qdio_free);
1238
1239 /**
1240 * qdio_allocate - allocate qdio queues and associated data
1241 * @init_data: initialization data
1242 */
qdio_allocate(struct qdio_initialize * init_data)1243 int qdio_allocate(struct qdio_initialize *init_data)
1244 {
1245 struct subchannel_id schid;
1246 struct qdio_irq *irq_ptr;
1247
1248 ccw_device_get_schid(init_data->cdev, &schid);
1249 DBF_EVENT("qallocate:%4x", schid.sch_no);
1250
1251 if ((init_data->no_input_qs && !init_data->input_handler) ||
1252 (init_data->no_output_qs && !init_data->output_handler))
1253 return -EINVAL;
1254
1255 if ((init_data->no_input_qs > QDIO_MAX_QUEUES_PER_IRQ) ||
1256 (init_data->no_output_qs > QDIO_MAX_QUEUES_PER_IRQ))
1257 return -EINVAL;
1258
1259 if ((!init_data->input_sbal_addr_array) ||
1260 (!init_data->output_sbal_addr_array))
1261 return -EINVAL;
1262
1263 /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */
1264 irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1265 if (!irq_ptr)
1266 goto out_err;
1267
1268 mutex_init(&irq_ptr->setup_mutex);
1269 if (qdio_allocate_dbf(init_data, irq_ptr))
1270 goto out_rel;
1271
1272 /*
1273 * Allocate a page for the chsc calls in qdio_establish.
1274 * Must be pre-allocated since a zfcp recovery will call
1275 * qdio_establish. In case of low memory and swap on a zfcp disk
1276 * we may not be able to allocate memory otherwise.
1277 */
1278 irq_ptr->chsc_page = get_zeroed_page(GFP_KERNEL);
1279 if (!irq_ptr->chsc_page)
1280 goto out_rel;
1281
1282 /* qdr is used in ccw1.cda which is u32 */
1283 irq_ptr->qdr = (struct qdr *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1284 if (!irq_ptr->qdr)
1285 goto out_rel;
1286
1287 if (qdio_allocate_qs(irq_ptr, init_data->no_input_qs,
1288 init_data->no_output_qs))
1289 goto out_rel;
1290
1291 init_data->cdev->private->qdio_data = irq_ptr;
1292 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1293 return 0;
1294 out_rel:
1295 qdio_release_memory(irq_ptr);
1296 out_err:
1297 return -ENOMEM;
1298 }
1299 EXPORT_SYMBOL_GPL(qdio_allocate);
1300
qdio_detect_hsicq(struct qdio_irq * irq_ptr)1301 static void qdio_detect_hsicq(struct qdio_irq *irq_ptr)
1302 {
1303 struct qdio_q *q = irq_ptr->input_qs[0];
1304 int i, use_cq = 0;
1305
1306 if (irq_ptr->nr_input_qs > 1 && queue_type(q) == QDIO_IQDIO_QFMT)
1307 use_cq = 1;
1308
1309 for_each_output_queue(irq_ptr, q, i) {
1310 if (use_cq) {
1311 if (multicast_outbound(q))
1312 continue;
1313 if (qdio_enable_async_operation(&q->u.out) < 0) {
1314 use_cq = 0;
1315 continue;
1316 }
1317 } else
1318 qdio_disable_async_operation(&q->u.out);
1319 }
1320 DBF_EVENT("use_cq:%d", use_cq);
1321 }
1322
1323 /**
1324 * qdio_establish - establish queues on a qdio subchannel
1325 * @init_data: initialization data
1326 */
qdio_establish(struct qdio_initialize * init_data)1327 int qdio_establish(struct qdio_initialize *init_data)
1328 {
1329 struct ccw_device *cdev = init_data->cdev;
1330 struct subchannel_id schid;
1331 struct qdio_irq *irq_ptr;
1332 int rc;
1333
1334 ccw_device_get_schid(cdev, &schid);
1335 DBF_EVENT("qestablish:%4x", schid.sch_no);
1336
1337 irq_ptr = cdev->private->qdio_data;
1338 if (!irq_ptr)
1339 return -ENODEV;
1340
1341 mutex_lock(&irq_ptr->setup_mutex);
1342 qdio_setup_irq(init_data);
1343
1344 rc = qdio_establish_thinint(irq_ptr);
1345 if (rc) {
1346 mutex_unlock(&irq_ptr->setup_mutex);
1347 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1348 return rc;
1349 }
1350
1351 /* establish q */
1352 irq_ptr->ccw.cmd_code = irq_ptr->equeue.cmd;
1353 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1354 irq_ptr->ccw.count = irq_ptr->equeue.count;
1355 irq_ptr->ccw.cda = (u32)((addr_t)irq_ptr->qdr);
1356
1357 spin_lock_irq(get_ccwdev_lock(cdev));
1358 ccw_device_set_options_mask(cdev, 0);
1359
1360 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ESTABLISH, 0, 0);
1361 spin_unlock_irq(get_ccwdev_lock(cdev));
1362 if (rc) {
1363 DBF_ERROR("%4x est IO ERR", irq_ptr->schid.sch_no);
1364 DBF_ERROR("rc:%4x", rc);
1365 mutex_unlock(&irq_ptr->setup_mutex);
1366 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1367 return rc;
1368 }
1369
1370 wait_event_interruptible_timeout(cdev->private->wait_q,
1371 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
1372 irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ);
1373
1374 if (irq_ptr->state != QDIO_IRQ_STATE_ESTABLISHED) {
1375 mutex_unlock(&irq_ptr->setup_mutex);
1376 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1377 return -EIO;
1378 }
1379
1380 qdio_setup_ssqd_info(irq_ptr);
1381
1382 qdio_detect_hsicq(irq_ptr);
1383
1384 /* qebsm is now setup if available, initialize buffer states */
1385 qdio_init_buf_states(irq_ptr);
1386
1387 mutex_unlock(&irq_ptr->setup_mutex);
1388 qdio_print_subchannel_info(irq_ptr, cdev);
1389 qdio_setup_debug_entries(irq_ptr, cdev);
1390 return 0;
1391 }
1392 EXPORT_SYMBOL_GPL(qdio_establish);
1393
1394 /**
1395 * qdio_activate - activate queues on a qdio subchannel
1396 * @cdev: associated cdev
1397 */
qdio_activate(struct ccw_device * cdev)1398 int qdio_activate(struct ccw_device *cdev)
1399 {
1400 struct subchannel_id schid;
1401 struct qdio_irq *irq_ptr;
1402 int rc;
1403
1404 ccw_device_get_schid(cdev, &schid);
1405 DBF_EVENT("qactivate:%4x", schid.sch_no);
1406
1407 irq_ptr = cdev->private->qdio_data;
1408 if (!irq_ptr)
1409 return -ENODEV;
1410
1411 mutex_lock(&irq_ptr->setup_mutex);
1412 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1413 rc = -EBUSY;
1414 goto out;
1415 }
1416
1417 irq_ptr->ccw.cmd_code = irq_ptr->aqueue.cmd;
1418 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1419 irq_ptr->ccw.count = irq_ptr->aqueue.count;
1420 irq_ptr->ccw.cda = 0;
1421
1422 spin_lock_irq(get_ccwdev_lock(cdev));
1423 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
1424
1425 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ACTIVATE,
1426 0, DOIO_DENY_PREFETCH);
1427 spin_unlock_irq(get_ccwdev_lock(cdev));
1428 if (rc) {
1429 DBF_ERROR("%4x act IO ERR", irq_ptr->schid.sch_no);
1430 DBF_ERROR("rc:%4x", rc);
1431 goto out;
1432 }
1433
1434 if (is_thinint_irq(irq_ptr))
1435 tiqdio_add_input_queues(irq_ptr);
1436
1437 /* wait for subchannel to become active */
1438 msleep(5);
1439
1440 switch (irq_ptr->state) {
1441 case QDIO_IRQ_STATE_STOPPED:
1442 case QDIO_IRQ_STATE_ERR:
1443 rc = -EIO;
1444 break;
1445 default:
1446 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
1447 rc = 0;
1448 }
1449 out:
1450 mutex_unlock(&irq_ptr->setup_mutex);
1451 return rc;
1452 }
1453 EXPORT_SYMBOL_GPL(qdio_activate);
1454
buf_in_between(int bufnr,int start,int count)1455 static inline int buf_in_between(int bufnr, int start, int count)
1456 {
1457 int end = add_buf(start, count);
1458
1459 if (end > start) {
1460 if (bufnr >= start && bufnr < end)
1461 return 1;
1462 else
1463 return 0;
1464 }
1465
1466 /* wrap-around case */
1467 if ((bufnr >= start && bufnr <= QDIO_MAX_BUFFERS_PER_Q) ||
1468 (bufnr < end))
1469 return 1;
1470 else
1471 return 0;
1472 }
1473
1474 /**
1475 * handle_inbound - reset processed input buffers
1476 * @q: queue containing the buffers
1477 * @callflags: flags
1478 * @bufnr: first buffer to process
1479 * @count: how many buffers are emptied
1480 */
handle_inbound(struct qdio_q * q,unsigned int callflags,int bufnr,int count)1481 static int handle_inbound(struct qdio_q *q, unsigned int callflags,
1482 int bufnr, int count)
1483 {
1484 int diff;
1485
1486 qperf_inc(q, inbound_call);
1487
1488 if (!q->u.in.polling)
1489 goto set;
1490
1491 /* protect against stop polling setting an ACK for an emptied slsb */
1492 if (count == QDIO_MAX_BUFFERS_PER_Q) {
1493 /* overwriting everything, just delete polling status */
1494 q->u.in.polling = 0;
1495 q->u.in.ack_count = 0;
1496 goto set;
1497 } else if (buf_in_between(q->u.in.ack_start, bufnr, count)) {
1498 if (is_qebsm(q)) {
1499 /* partial overwrite, just update ack_start */
1500 diff = add_buf(bufnr, count);
1501 diff = sub_buf(diff, q->u.in.ack_start);
1502 q->u.in.ack_count -= diff;
1503 if (q->u.in.ack_count <= 0) {
1504 q->u.in.polling = 0;
1505 q->u.in.ack_count = 0;
1506 goto set;
1507 }
1508 q->u.in.ack_start = add_buf(q->u.in.ack_start, diff);
1509 }
1510 else
1511 /* the only ACK will be deleted, so stop polling */
1512 q->u.in.polling = 0;
1513 }
1514
1515 set:
1516 count = set_buf_states(q, bufnr, SLSB_CU_INPUT_EMPTY, count);
1517 atomic_add(count, &q->nr_buf_used);
1518
1519 if (need_siga_in(q))
1520 return qdio_siga_input(q);
1521
1522 return 0;
1523 }
1524
1525 /**
1526 * handle_outbound - process filled outbound buffers
1527 * @q: queue containing the buffers
1528 * @callflags: flags
1529 * @bufnr: first buffer to process
1530 * @count: how many buffers are filled
1531 */
handle_outbound(struct qdio_q * q,unsigned int callflags,int bufnr,int count)1532 static int handle_outbound(struct qdio_q *q, unsigned int callflags,
1533 int bufnr, int count)
1534 {
1535 const unsigned int scan_threshold = q->irq_ptr->scan_threshold;
1536 unsigned char state = 0;
1537 int used, rc = 0;
1538
1539 qperf_inc(q, outbound_call);
1540
1541 count = set_buf_states(q, bufnr, SLSB_CU_OUTPUT_PRIMED, count);
1542 used = atomic_add_return(count, &q->nr_buf_used);
1543
1544 if (used == QDIO_MAX_BUFFERS_PER_Q)
1545 qperf_inc(q, outbound_queue_full);
1546
1547 if (callflags & QDIO_FLAG_PCI_OUT) {
1548 q->u.out.pci_out_enabled = 1;
1549 qperf_inc(q, pci_request_int);
1550 } else
1551 q->u.out.pci_out_enabled = 0;
1552
1553 if (queue_type(q) == QDIO_IQDIO_QFMT) {
1554 unsigned long phys_aob = 0;
1555
1556 /* One SIGA-W per buffer required for unicast HSI */
1557 WARN_ON_ONCE(count > 1 && !multicast_outbound(q));
1558
1559 if (q->u.out.use_cq)
1560 phys_aob = qdio_aob_for_buffer(&q->u.out, bufnr);
1561
1562 rc = qdio_kick_outbound_q(q, phys_aob);
1563 } else if (need_siga_sync(q)) {
1564 rc = qdio_siga_sync_q(q);
1565 } else if (count < QDIO_MAX_BUFFERS_PER_Q &&
1566 get_buf_state(q, prev_buf(bufnr), &state, 0) > 0 &&
1567 state == SLSB_CU_OUTPUT_PRIMED) {
1568 /* The previous buffer is not processed yet, tack on. */
1569 qperf_inc(q, fast_requeue);
1570 } else {
1571 rc = qdio_kick_outbound_q(q, 0);
1572 }
1573
1574 /* Let drivers implement their own completion scanning: */
1575 if (!scan_threshold)
1576 return rc;
1577
1578 /* in case of SIGA errors we must process the error immediately */
1579 if (used >= scan_threshold || rc)
1580 qdio_tasklet_schedule(q);
1581 else
1582 /* free the SBALs in case of no further traffic */
1583 if (!timer_pending(&q->u.out.timer) &&
1584 likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE))
1585 mod_timer(&q->u.out.timer, jiffies + HZ);
1586 return rc;
1587 }
1588
1589 /**
1590 * do_QDIO - process input or output buffers
1591 * @cdev: associated ccw_device for the qdio subchannel
1592 * @callflags: input or output and special flags from the program
1593 * @q_nr: queue number
1594 * @bufnr: buffer number
1595 * @count: how many buffers to process
1596 */
do_QDIO(struct ccw_device * cdev,unsigned int callflags,int q_nr,unsigned int bufnr,unsigned int count)1597 int do_QDIO(struct ccw_device *cdev, unsigned int callflags,
1598 int q_nr, unsigned int bufnr, unsigned int count)
1599 {
1600 struct qdio_irq *irq_ptr;
1601
1602 if (bufnr >= QDIO_MAX_BUFFERS_PER_Q || count > QDIO_MAX_BUFFERS_PER_Q)
1603 return -EINVAL;
1604
1605 irq_ptr = cdev->private->qdio_data;
1606 if (!irq_ptr)
1607 return -ENODEV;
1608
1609 DBF_DEV_EVENT(DBF_INFO, irq_ptr,
1610 "do%02x b:%02x c:%02x", callflags, bufnr, count);
1611
1612 if (irq_ptr->state != QDIO_IRQ_STATE_ACTIVE)
1613 return -EIO;
1614 if (!count)
1615 return 0;
1616 if (callflags & QDIO_FLAG_SYNC_INPUT)
1617 return handle_inbound(irq_ptr->input_qs[q_nr],
1618 callflags, bufnr, count);
1619 else if (callflags & QDIO_FLAG_SYNC_OUTPUT)
1620 return handle_outbound(irq_ptr->output_qs[q_nr],
1621 callflags, bufnr, count);
1622 return -EINVAL;
1623 }
1624 EXPORT_SYMBOL_GPL(do_QDIO);
1625
1626 /**
1627 * qdio_start_irq - process input buffers
1628 * @cdev: associated ccw_device for the qdio subchannel
1629 * @nr: input queue number
1630 *
1631 * Return codes
1632 * 0 - success
1633 * 1 - irqs not started since new data is available
1634 */
qdio_start_irq(struct ccw_device * cdev,int nr)1635 int qdio_start_irq(struct ccw_device *cdev, int nr)
1636 {
1637 struct qdio_q *q;
1638 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1639
1640 if (!irq_ptr)
1641 return -ENODEV;
1642 q = irq_ptr->input_qs[nr];
1643
1644 clear_nonshared_ind(irq_ptr);
1645 qdio_stop_polling(q);
1646 clear_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state);
1647
1648 /*
1649 * We need to check again to not lose initiative after
1650 * resetting the ACK state.
1651 */
1652 if (test_nonshared_ind(irq_ptr))
1653 goto rescan;
1654 if (!qdio_inbound_q_done(q, q->first_to_check))
1655 goto rescan;
1656 return 0;
1657
1658 rescan:
1659 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
1660 &q->u.in.queue_irq_state))
1661 return 0;
1662 else
1663 return 1;
1664
1665 }
1666 EXPORT_SYMBOL(qdio_start_irq);
1667
__qdio_inspect_queue(struct qdio_q * q,unsigned int * bufnr,unsigned int * error)1668 static int __qdio_inspect_queue(struct qdio_q *q, unsigned int *bufnr,
1669 unsigned int *error)
1670 {
1671 unsigned int start = q->first_to_check;
1672 int count;
1673
1674 count = q->is_input_q ? qdio_inbound_q_moved(q, start) :
1675 qdio_outbound_q_moved(q, start);
1676 if (count == 0)
1677 return 0;
1678
1679 *bufnr = start;
1680 *error = q->qdio_error;
1681
1682 /* for the next time */
1683 q->first_to_check = add_buf(start, count);
1684 q->qdio_error = 0;
1685
1686 return count;
1687 }
1688
qdio_inspect_queue(struct ccw_device * cdev,unsigned int nr,bool is_input,unsigned int * bufnr,unsigned int * error)1689 int qdio_inspect_queue(struct ccw_device *cdev, unsigned int nr, bool is_input,
1690 unsigned int *bufnr, unsigned int *error)
1691 {
1692 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1693 struct qdio_q *q;
1694
1695 if (!irq_ptr)
1696 return -ENODEV;
1697 q = is_input ? irq_ptr->input_qs[nr] : irq_ptr->output_qs[nr];
1698
1699 if (need_siga_sync(q))
1700 qdio_siga_sync_q(q);
1701
1702 return __qdio_inspect_queue(q, bufnr, error);
1703 }
1704 EXPORT_SYMBOL_GPL(qdio_inspect_queue);
1705
1706 /**
1707 * qdio_get_next_buffers - process input buffers
1708 * @cdev: associated ccw_device for the qdio subchannel
1709 * @nr: input queue number
1710 * @bufnr: first filled buffer number
1711 * @error: buffers are in error state
1712 *
1713 * Return codes
1714 * < 0 - error
1715 * = 0 - no new buffers found
1716 * > 0 - number of processed buffers
1717 */
qdio_get_next_buffers(struct ccw_device * cdev,int nr,int * bufnr,int * error)1718 int qdio_get_next_buffers(struct ccw_device *cdev, int nr, int *bufnr,
1719 int *error)
1720 {
1721 struct qdio_q *q;
1722 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1723
1724 if (!irq_ptr)
1725 return -ENODEV;
1726 q = irq_ptr->input_qs[nr];
1727
1728 /*
1729 * Cannot rely on automatic sync after interrupt since queues may
1730 * also be examined without interrupt.
1731 */
1732 if (need_siga_sync(q))
1733 qdio_sync_queues(q);
1734
1735 qdio_check_outbound_pci_queues(irq_ptr);
1736
1737 /* Note: upper-layer MUST stop processing immediately here ... */
1738 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
1739 return -EIO;
1740
1741 return __qdio_inspect_queue(q, bufnr, error);
1742 }
1743 EXPORT_SYMBOL(qdio_get_next_buffers);
1744
1745 /**
1746 * qdio_stop_irq - disable interrupt processing for the device
1747 * @cdev: associated ccw_device for the qdio subchannel
1748 * @nr: input queue number
1749 *
1750 * Return codes
1751 * 0 - interrupts were already disabled
1752 * 1 - interrupts successfully disabled
1753 */
qdio_stop_irq(struct ccw_device * cdev,int nr)1754 int qdio_stop_irq(struct ccw_device *cdev, int nr)
1755 {
1756 struct qdio_q *q;
1757 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1758
1759 if (!irq_ptr)
1760 return -ENODEV;
1761 q = irq_ptr->input_qs[nr];
1762
1763 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
1764 &q->u.in.queue_irq_state))
1765 return 0;
1766 else
1767 return 1;
1768 }
1769 EXPORT_SYMBOL(qdio_stop_irq);
1770
1771 /**
1772 * qdio_pnso_brinfo() - perform network subchannel op #0 - bridge info.
1773 * @schid: Subchannel ID.
1774 * @cnc: Boolean Change-Notification Control
1775 * @response: Response code will be stored at this address
1776 * @cb: Callback function will be executed for each element
1777 * of the address list
1778 * @priv: Pointer to pass to the callback function.
1779 *
1780 * Performs "Store-network-bridging-information list" operation and calls
1781 * the callback function for every entry in the list. If "change-
1782 * notification-control" is set, further changes in the address list
1783 * will be reported via the IPA command.
1784 */
qdio_pnso_brinfo(struct subchannel_id schid,int cnc,u16 * response,void (* cb)(void * priv,enum qdio_brinfo_entry_type type,void * entry),void * priv)1785 int qdio_pnso_brinfo(struct subchannel_id schid,
1786 int cnc, u16 *response,
1787 void (*cb)(void *priv, enum qdio_brinfo_entry_type type,
1788 void *entry),
1789 void *priv)
1790 {
1791 struct chsc_pnso_area *rr;
1792 int rc;
1793 u32 prev_instance = 0;
1794 int isfirstblock = 1;
1795 int i, size, elems;
1796
1797 rr = (struct chsc_pnso_area *)get_zeroed_page(GFP_KERNEL);
1798 if (rr == NULL)
1799 return -ENOMEM;
1800 do {
1801 /* on the first iteration, naihdr.resume_token will be zero */
1802 rc = chsc_pnso_brinfo(schid, rr, rr->naihdr.resume_token, cnc);
1803 if (rc != 0 && rc != -EBUSY)
1804 goto out;
1805 if (rr->response.code != 1) {
1806 rc = -EIO;
1807 continue;
1808 } else
1809 rc = 0;
1810
1811 if (cb == NULL)
1812 continue;
1813
1814 size = rr->naihdr.naids;
1815 elems = (rr->response.length -
1816 sizeof(struct chsc_header) -
1817 sizeof(struct chsc_brinfo_naihdr)) /
1818 size;
1819
1820 if (!isfirstblock && (rr->naihdr.instance != prev_instance)) {
1821 /* Inform the caller that they need to scrap */
1822 /* the data that was already reported via cb */
1823 rc = -EAGAIN;
1824 break;
1825 }
1826 isfirstblock = 0;
1827 prev_instance = rr->naihdr.instance;
1828 for (i = 0; i < elems; i++)
1829 switch (size) {
1830 case sizeof(struct qdio_brinfo_entry_l3_ipv6):
1831 (*cb)(priv, l3_ipv6_addr,
1832 &rr->entries.l3_ipv6[i]);
1833 break;
1834 case sizeof(struct qdio_brinfo_entry_l3_ipv4):
1835 (*cb)(priv, l3_ipv4_addr,
1836 &rr->entries.l3_ipv4[i]);
1837 break;
1838 case sizeof(struct qdio_brinfo_entry_l2):
1839 (*cb)(priv, l2_addr_lnid,
1840 &rr->entries.l2[i]);
1841 break;
1842 default:
1843 WARN_ON_ONCE(1);
1844 rc = -EIO;
1845 goto out;
1846 }
1847 } while (rr->response.code == 0x0107 || /* channel busy */
1848 (rr->response.code == 1 && /* list stored */
1849 /* resume token is non-zero => list incomplete */
1850 (rr->naihdr.resume_token.t1 || rr->naihdr.resume_token.t2)));
1851 (*response) = rr->response.code;
1852
1853 out:
1854 free_page((unsigned long)rr);
1855 return rc;
1856 }
1857 EXPORT_SYMBOL_GPL(qdio_pnso_brinfo);
1858
init_QDIO(void)1859 static int __init init_QDIO(void)
1860 {
1861 int rc;
1862
1863 rc = qdio_debug_init();
1864 if (rc)
1865 return rc;
1866 rc = qdio_setup_init();
1867 if (rc)
1868 goto out_debug;
1869 rc = tiqdio_allocate_memory();
1870 if (rc)
1871 goto out_cache;
1872 rc = tiqdio_register_thinints();
1873 if (rc)
1874 goto out_ti;
1875 return 0;
1876
1877 out_ti:
1878 tiqdio_free_memory();
1879 out_cache:
1880 qdio_setup_exit();
1881 out_debug:
1882 qdio_debug_exit();
1883 return rc;
1884 }
1885
exit_QDIO(void)1886 static void __exit exit_QDIO(void)
1887 {
1888 tiqdio_unregister_thinints();
1889 tiqdio_free_memory();
1890 qdio_setup_exit();
1891 qdio_debug_exit();
1892 }
1893
1894 module_init(init_QDIO);
1895 module_exit(exit_QDIO);
1896