1 // SPDX-License-Identifier: GPL-2.0
3 * Linux for s390 qdio support, buffer handling, qdio API and module support.
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>
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>
17 #include <linux/atomic.h>
18 #include <asm/debug.h>
26 #include "qdio_debug.h"
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");
33 static inline int do_siga_sync(unsigned long schid,
34 unsigned int out_mask, unsigned int in_mask,
37 register unsigned long __fc asm ("0") = fc;
38 register unsigned long __schid asm ("1") = schid;
39 register unsigned long out asm ("2") = out_mask;
40 register unsigned long in asm ("3") = in_mask;
48 : "d" (__fc), "d" (__schid), "d" (out), "d" (in) : "cc");
52 static inline int do_siga_input(unsigned long schid, unsigned int mask,
55 register unsigned long __fc asm ("0") = fc;
56 register unsigned long __schid asm ("1") = schid;
57 register unsigned long __mask asm ("2") = mask;
65 : "d" (__fc), "d" (__schid), "d" (__mask) : "cc");
70 * do_siga_output - perform SIGA-w/wt function
71 * @schid: subchannel id or in case of QEBSM the subchannel token
72 * @mask: which output queues to process
73 * @bb: busy bit indicator, set only if SIGA-w/wt could not access a buffer
74 * @fc: function code to perform
75 * @aob: asynchronous operation block
77 * Returns condition code.
78 * Note: For IQDC unicast queues only the highest priority queue is processed.
80 static inline int do_siga_output(unsigned long schid, unsigned long mask,
81 unsigned int *bb, unsigned int fc,
84 register unsigned long __fc asm("0") = fc;
85 register unsigned long __schid asm("1") = schid;
86 register unsigned long __mask asm("2") = mask;
87 register unsigned long __aob asm("3") = aob;
94 : "=d" (cc), "+d" (__fc), "+d" (__aob)
95 : "d" (__schid), "d" (__mask)
102 * qdio_do_eqbs - extract buffer states for QEBSM
103 * @q: queue to manipulate
104 * @state: state of the extracted buffers
105 * @start: buffer number to start at
106 * @count: count of buffers to examine
107 * @auto_ack: automatically acknowledge buffers
109 * Returns the number of successfully extracted equal buffer states.
110 * Stops processing if a state is different from the last buffers state.
112 static int qdio_do_eqbs(struct qdio_q *q, unsigned char *state,
113 int start, int count, int auto_ack)
115 int tmp_count = count, tmp_start = start, nr = q->nr;
116 unsigned int ccq = 0;
121 nr += q->irq_ptr->nr_input_qs;
123 ccq = do_eqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count,
129 /* all done, or next buffer state different */
130 return count - tmp_count;
132 /* not all buffers processed */
133 qperf_inc(q, eqbs_partial);
134 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "EQBS part:%02x",
136 return count - tmp_count;
138 /* no buffer processed */
139 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "EQBS again:%2d", ccq);
142 DBF_ERROR("%4x ccq:%3d", SCH_NO(q), ccq);
143 DBF_ERROR("%4x EQBS ERROR", SCH_NO(q));
144 DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
145 q->handler(q->irq_ptr->cdev, QDIO_ERROR_GET_BUF_STATE, q->nr,
146 q->first_to_check, count, q->irq_ptr->int_parm);
152 * qdio_do_sqbs - set buffer states for QEBSM
153 * @q: queue to manipulate
154 * @state: new state of the buffers
155 * @start: first buffer number to change
156 * @count: how many buffers to change
158 * Returns the number of successfully changed buffers.
159 * Does retrying until the specified count of buffer states is set or an
162 static int qdio_do_sqbs(struct qdio_q *q, unsigned char state, int start,
165 unsigned int ccq = 0;
166 int tmp_count = count, tmp_start = start;
174 nr += q->irq_ptr->nr_input_qs;
176 ccq = do_sqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count);
181 /* all done, or active buffer adapter-owned */
182 WARN_ON_ONCE(tmp_count);
183 return count - tmp_count;
185 /* not all buffers processed */
186 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "SQBS again:%2d", ccq);
187 qperf_inc(q, sqbs_partial);
190 DBF_ERROR("%4x ccq:%3d", SCH_NO(q), ccq);
191 DBF_ERROR("%4x SQBS ERROR", SCH_NO(q));
192 DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
193 q->handler(q->irq_ptr->cdev, QDIO_ERROR_SET_BUF_STATE, q->nr,
194 q->first_to_check, count, q->irq_ptr->int_parm);
200 * Returns number of examined buffers and their common state in *state.
201 * Requested number of buffers-to-examine must be > 0.
203 static inline int get_buf_states(struct qdio_q *q, unsigned int bufnr,
204 unsigned char *state, unsigned int count,
205 int auto_ack, int merge_pending)
207 unsigned char __state = 0;
211 return qdio_do_eqbs(q, state, bufnr, count, auto_ack);
213 /* get initial state: */
214 __state = q->slsb.val[bufnr];
216 /* Bail out early if there is no work on the queue: */
217 if (__state & SLSB_OWNER_CU)
220 if (merge_pending && __state == SLSB_P_OUTPUT_PENDING)
221 __state = SLSB_P_OUTPUT_EMPTY;
223 for (; i < count; i++) {
224 bufnr = next_buf(bufnr);
226 /* merge PENDING into EMPTY: */
228 q->slsb.val[bufnr] == SLSB_P_OUTPUT_PENDING &&
229 __state == SLSB_P_OUTPUT_EMPTY)
232 /* stop if next state differs from initial state: */
233 if (q->slsb.val[bufnr] != __state)
242 static inline int get_buf_state(struct qdio_q *q, unsigned int bufnr,
243 unsigned char *state, int auto_ack)
245 return get_buf_states(q, bufnr, state, 1, auto_ack, 0);
248 /* wrap-around safe setting of slsb states, returns number of changed buffers */
249 static inline int set_buf_states(struct qdio_q *q, int bufnr,
250 unsigned char state, int count)
255 return qdio_do_sqbs(q, state, bufnr, count);
257 /* Ensure that all preceding changes to the SBALs are visible: */
260 for (i = 0; i < count; i++) {
261 WRITE_ONCE(q->slsb.val[bufnr], state);
262 bufnr = next_buf(bufnr);
265 /* Make our SLSB changes visible: */
271 static inline int set_buf_state(struct qdio_q *q, int bufnr,
274 return set_buf_states(q, bufnr, state, 1);
277 /* set slsb states to initial state */
278 static void qdio_init_buf_states(struct qdio_irq *irq_ptr)
283 for_each_input_queue(irq_ptr, q, i)
284 set_buf_states(q, 0, SLSB_P_INPUT_NOT_INIT,
285 QDIO_MAX_BUFFERS_PER_Q);
286 for_each_output_queue(irq_ptr, q, i)
287 set_buf_states(q, 0, SLSB_P_OUTPUT_NOT_INIT,
288 QDIO_MAX_BUFFERS_PER_Q);
291 static inline int qdio_siga_sync(struct qdio_q *q, unsigned int output,
294 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
295 unsigned int fc = QDIO_SIGA_SYNC;
298 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-s:%1d", q->nr);
299 qperf_inc(q, siga_sync);
302 schid = q->irq_ptr->sch_token;
303 fc |= QDIO_SIGA_QEBSM_FLAG;
306 cc = do_siga_sync(schid, output, input, fc);
308 DBF_ERROR("%4x SIGA-S:%2d", SCH_NO(q), cc);
309 return (cc) ? -EIO : 0;
312 static inline int qdio_siga_sync_q(struct qdio_q *q)
315 return qdio_siga_sync(q, 0, q->mask);
317 return qdio_siga_sync(q, q->mask, 0);
320 static int qdio_siga_output(struct qdio_q *q, unsigned int count,
321 unsigned int *busy_bit, unsigned long aob)
323 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
324 unsigned int fc = QDIO_SIGA_WRITE;
328 if (queue_type(q) == QDIO_IQDIO_QFMT && !multicast_outbound(q)) {
330 fc = QDIO_SIGA_WRITEM;
332 fc = QDIO_SIGA_WRITEQ;
336 schid = q->irq_ptr->sch_token;
337 fc |= QDIO_SIGA_QEBSM_FLAG;
340 cc = do_siga_output(schid, q->mask, busy_bit, fc, aob);
342 /* hipersocket busy condition */
343 if (unlikely(*busy_bit)) {
347 start_time = get_tod_clock_fast();
350 if (get_tod_clock_fast() - start_time < QDIO_BUSY_BIT_PATIENCE)
354 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr,
355 "%4x cc2 BB1:%1d", SCH_NO(q), q->nr);
356 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "count:%u", retries);
361 static inline int qdio_siga_input(struct qdio_q *q)
363 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
364 unsigned int fc = QDIO_SIGA_READ;
367 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-r:%1d", q->nr);
368 qperf_inc(q, siga_read);
371 schid = q->irq_ptr->sch_token;
372 fc |= QDIO_SIGA_QEBSM_FLAG;
375 cc = do_siga_input(schid, q->mask, fc);
377 DBF_ERROR("%4x SIGA-R:%2d", SCH_NO(q), cc);
378 return (cc) ? -EIO : 0;
381 #define qdio_siga_sync_out(q) qdio_siga_sync(q, ~0U, 0)
382 #define qdio_siga_sync_all(q) qdio_siga_sync(q, ~0U, ~0U)
384 static inline void qdio_sync_queues(struct qdio_q *q)
386 /* PCI capable outbound queues will also be scanned so sync them too */
387 if (pci_out_supported(q->irq_ptr))
388 qdio_siga_sync_all(q);
393 int debug_get_buf_state(struct qdio_q *q, unsigned int bufnr,
394 unsigned char *state)
396 if (need_siga_sync(q))
398 return get_buf_state(q, bufnr, state, 0);
401 static inline void qdio_stop_polling(struct qdio_q *q)
403 if (!q->u.in.batch_count)
406 qperf_inc(q, stop_polling);
408 /* show the card that we are not polling anymore */
409 set_buf_states(q, q->u.in.batch_start, SLSB_P_INPUT_NOT_INIT,
410 q->u.in.batch_count);
411 q->u.in.batch_count = 0;
414 static inline void account_sbals(struct qdio_q *q, unsigned int count)
418 q->q_stats.nr_sbal_total += count;
419 if (count == QDIO_MAX_BUFFERS_MASK) {
420 q->q_stats.nr_sbals[7]++;
424 q->q_stats.nr_sbals[pos]++;
427 static void process_buffer_error(struct qdio_q *q, unsigned int start,
430 q->qdio_error = QDIO_ERROR_SLSB_STATE;
432 /* special handling for no target buffer empty */
433 if (queue_type(q) == QDIO_IQDIO_QFMT && !q->is_input_q &&
434 q->sbal[start]->element[15].sflags == 0x10) {
435 qperf_inc(q, target_full);
436 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "OUTFULL FTC:%02x", start);
440 DBF_ERROR("%4x BUF ERROR", SCH_NO(q));
441 DBF_ERROR((q->is_input_q) ? "IN:%2d" : "OUT:%2d", q->nr);
442 DBF_ERROR("FTC:%3d C:%3d", start, count);
443 DBF_ERROR("F14:%2x F15:%2x",
444 q->sbal[start]->element[14].sflags,
445 q->sbal[start]->element[15].sflags);
448 static inline void inbound_handle_work(struct qdio_q *q, unsigned int start,
449 int count, bool auto_ack)
451 /* ACK the newest SBAL: */
453 set_buf_state(q, add_buf(start, count - 1), SLSB_P_INPUT_ACK);
455 if (!q->u.in.batch_count)
456 q->u.in.batch_start = start;
457 q->u.in.batch_count += count;
460 static int get_inbound_buffer_frontier(struct qdio_q *q, unsigned int start)
462 unsigned char state = 0;
465 q->timestamp = get_tod_clock_fast();
468 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
471 count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
476 * No siga sync here, as a PCI or we after a thin interrupt
477 * already sync'ed the queues.
479 count = get_buf_states(q, start, &state, count, 1, 0);
484 case SLSB_P_INPUT_PRIMED:
485 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in prim:%1d %02x", q->nr,
488 inbound_handle_work(q, start, count, is_qebsm(q));
489 if (atomic_sub_return(count, &q->nr_buf_used) == 0)
490 qperf_inc(q, inbound_queue_full);
491 if (q->irq_ptr->perf_stat_enabled)
492 account_sbals(q, count);
494 case SLSB_P_INPUT_ERROR:
495 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in err:%1d %02x", q->nr,
498 process_buffer_error(q, start, count);
499 inbound_handle_work(q, start, count, false);
500 if (atomic_sub_return(count, &q->nr_buf_used) == 0)
501 qperf_inc(q, inbound_queue_full);
502 if (q->irq_ptr->perf_stat_enabled)
503 account_sbals_error(q, count);
505 case SLSB_CU_INPUT_EMPTY:
506 if (q->irq_ptr->perf_stat_enabled)
507 q->q_stats.nr_sbal_nop++;
508 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in nop:%1d %#02x",
511 case SLSB_P_INPUT_NOT_INIT:
512 case SLSB_P_INPUT_ACK:
513 /* We should never see this state, throw a WARN: */
515 dev_WARN_ONCE(&q->irq_ptr->cdev->dev, 1,
516 "found state %#x at index %u on queue %u\n",
517 state, start, q->nr);
522 static int qdio_inbound_q_moved(struct qdio_q *q, unsigned int start)
526 count = get_inbound_buffer_frontier(q, start);
528 if (count && !is_thinint_irq(q->irq_ptr) && MACHINE_IS_LPAR)
529 q->u.in.timestamp = get_tod_clock();
534 static inline int qdio_inbound_q_done(struct qdio_q *q, unsigned int start)
536 unsigned char state = 0;
538 if (!atomic_read(&q->nr_buf_used))
541 if (need_siga_sync(q))
543 get_buf_state(q, start, &state, 0);
545 if (state == SLSB_P_INPUT_PRIMED || state == SLSB_P_INPUT_ERROR)
546 /* more work coming */
549 if (is_thinint_irq(q->irq_ptr))
552 /* don't poll under z/VM */
557 * At this point we know, that inbound first_to_check
558 * has (probably) not moved (see qdio_inbound_processing).
560 if (get_tod_clock_fast() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) {
561 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in done:%02x", start);
567 static inline void qdio_handle_aobs(struct qdio_q *q, int start, int count)
569 unsigned char state = 0;
572 for (j = 0; j < count; ++j) {
573 get_buf_state(q, b, &state, 0);
574 if (state == SLSB_P_OUTPUT_PENDING) {
575 struct qaob *aob = q->u.out.aobs[b];
579 q->u.out.sbal_state[b].flags |=
580 QDIO_OUTBUF_STATE_FLAG_PENDING;
581 q->u.out.aobs[b] = NULL;
587 static inline unsigned long qdio_aob_for_buffer(struct qdio_output_q *q,
590 unsigned long phys_aob = 0;
592 if (!q->aobs[bufnr]) {
593 struct qaob *aob = qdio_allocate_aob();
594 q->aobs[bufnr] = aob;
596 if (q->aobs[bufnr]) {
597 q->aobs[bufnr]->user1 = (u64) q->sbal_state[bufnr].user;
598 phys_aob = virt_to_phys(q->aobs[bufnr]);
599 WARN_ON_ONCE(phys_aob & 0xFF);
602 q->sbal_state[bufnr].flags = 0;
606 static void qdio_kick_handler(struct qdio_q *q, unsigned int start,
609 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
613 qperf_inc(q, inbound_handler);
614 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "kih s:%02x c:%02x", start, count);
616 qperf_inc(q, outbound_handler);
617 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "koh: s:%02x c:%02x",
621 q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr, start, count,
622 q->irq_ptr->int_parm);
624 /* for the next time */
628 static inline int qdio_tasklet_schedule(struct qdio_q *q)
630 if (likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE)) {
631 tasklet_schedule(&q->tasklet);
637 static void __qdio_inbound_processing(struct qdio_q *q)
639 unsigned int start = q->first_to_check;
642 qperf_inc(q, tasklet_inbound);
644 count = qdio_inbound_q_moved(q, start);
648 qdio_kick_handler(q, start, count);
649 start = add_buf(start, count);
650 q->first_to_check = start;
652 if (!qdio_inbound_q_done(q, start)) {
653 /* means poll time is not yet over */
654 qperf_inc(q, tasklet_inbound_resched);
655 if (!qdio_tasklet_schedule(q))
659 qdio_stop_polling(q);
661 * We need to check again to not lose initiative after
662 * resetting the ACK state.
664 if (!qdio_inbound_q_done(q, start)) {
665 qperf_inc(q, tasklet_inbound_resched2);
666 qdio_tasklet_schedule(q);
670 void qdio_inbound_processing(unsigned long data)
672 struct qdio_q *q = (struct qdio_q *)data;
673 __qdio_inbound_processing(q);
676 static int get_outbound_buffer_frontier(struct qdio_q *q, unsigned int start)
678 unsigned char state = 0;
681 q->timestamp = get_tod_clock_fast();
683 if (need_siga_sync(q))
684 if (((queue_type(q) != QDIO_IQDIO_QFMT) &&
685 !pci_out_supported(q->irq_ptr)) ||
686 (queue_type(q) == QDIO_IQDIO_QFMT &&
687 multicast_outbound(q)))
690 count = atomic_read(&q->nr_buf_used);
694 count = get_buf_states(q, start, &state, count, 0, q->u.out.use_cq);
699 case SLSB_P_OUTPUT_EMPTY:
700 case SLSB_P_OUTPUT_PENDING:
701 /* the adapter got it */
702 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr,
703 "out empty:%1d %02x", q->nr, count);
705 atomic_sub(count, &q->nr_buf_used);
706 if (q->irq_ptr->perf_stat_enabled)
707 account_sbals(q, count);
709 case SLSB_P_OUTPUT_ERROR:
710 process_buffer_error(q, start, count);
711 atomic_sub(count, &q->nr_buf_used);
712 if (q->irq_ptr->perf_stat_enabled)
713 account_sbals_error(q, count);
715 case SLSB_CU_OUTPUT_PRIMED:
716 /* the adapter has not fetched the output yet */
717 if (q->irq_ptr->perf_stat_enabled)
718 q->q_stats.nr_sbal_nop++;
719 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out primed:%1d",
722 case SLSB_P_OUTPUT_HALTED:
724 case SLSB_P_OUTPUT_NOT_INIT:
725 /* We should never see this state, throw a WARN: */
727 dev_WARN_ONCE(&q->irq_ptr->cdev->dev, 1,
728 "found state %#x at index %u on queue %u\n",
729 state, start, q->nr);
734 /* all buffers processed? */
735 static inline int qdio_outbound_q_done(struct qdio_q *q)
737 return atomic_read(&q->nr_buf_used) == 0;
740 static inline int qdio_outbound_q_moved(struct qdio_q *q, unsigned int start)
744 count = get_outbound_buffer_frontier(q, start);
747 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out moved:%1d", q->nr);
749 qdio_handle_aobs(q, start, count);
755 static int qdio_kick_outbound_q(struct qdio_q *q, unsigned int count,
759 unsigned int busy_bit;
761 if (!need_siga_out(q))
764 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w:%1d", q->nr);
766 qperf_inc(q, siga_write);
768 cc = qdio_siga_output(q, count, &busy_bit, aob);
774 while (++retries < QDIO_BUSY_BIT_RETRIES) {
775 mdelay(QDIO_BUSY_BIT_RETRY_DELAY);
778 DBF_ERROR("%4x cc2 BBC:%1d", SCH_NO(q), q->nr);
781 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w cc2:%1d", q->nr);
787 DBF_ERROR("%4x SIGA-W:%1d", SCH_NO(q), cc);
792 DBF_ERROR("%4x cc2 BB2:%1d", SCH_NO(q), q->nr);
793 DBF_ERROR("count:%u", retries);
798 static void __qdio_outbound_processing(struct qdio_q *q)
800 unsigned int start = q->first_to_check;
803 qperf_inc(q, tasklet_outbound);
804 WARN_ON_ONCE(atomic_read(&q->nr_buf_used) < 0);
806 count = qdio_outbound_q_moved(q, start);
808 q->first_to_check = add_buf(start, count);
809 qdio_kick_handler(q, start, count);
812 if (queue_type(q) == QDIO_ZFCP_QFMT && !pci_out_supported(q->irq_ptr) &&
813 !qdio_outbound_q_done(q))
816 if (q->u.out.pci_out_enabled)
820 * Now we know that queue type is either qeth without pci enabled
821 * or HiperSockets. Make sure buffer switch from PRIMED to EMPTY
822 * is noticed and outbound_handler is called after some time.
824 if (qdio_outbound_q_done(q))
825 del_timer_sync(&q->u.out.timer);
827 if (!timer_pending(&q->u.out.timer) &&
828 likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE))
829 mod_timer(&q->u.out.timer, jiffies + 10 * HZ);
833 qdio_tasklet_schedule(q);
836 /* outbound tasklet */
837 void qdio_outbound_processing(unsigned long data)
839 struct qdio_q *q = (struct qdio_q *)data;
840 __qdio_outbound_processing(q);
843 void qdio_outbound_timer(struct timer_list *t)
845 struct qdio_q *q = from_timer(q, t, u.out.timer);
847 qdio_tasklet_schedule(q);
850 static inline void qdio_check_outbound_pci_queues(struct qdio_irq *irq)
855 if (!pci_out_supported(irq) || !irq->scan_threshold)
858 for_each_output_queue(irq, out, i)
859 if (!qdio_outbound_q_done(out))
860 qdio_tasklet_schedule(out);
863 void tiqdio_inbound_processing(unsigned long data)
865 struct qdio_q *q = (struct qdio_q *)data;
867 if (need_siga_sync(q) && need_siga_sync_after_ai(q))
870 /* The interrupt could be caused by a PCI request: */
871 qdio_check_outbound_pci_queues(q->irq_ptr);
873 __qdio_inbound_processing(q);
876 static inline void qdio_set_state(struct qdio_irq *irq_ptr,
877 enum qdio_irq_states state)
879 DBF_DEV_EVENT(DBF_INFO, irq_ptr, "newstate: %1d", state);
881 irq_ptr->state = state;
885 static void qdio_irq_check_sense(struct qdio_irq *irq_ptr, struct irb *irb)
887 if (irb->esw.esw0.erw.cons) {
888 DBF_ERROR("%4x sense:", irq_ptr->schid.sch_no);
889 DBF_ERROR_HEX(irb, 64);
890 DBF_ERROR_HEX(irb->ecw, 64);
894 /* PCI interrupt handler */
895 static void qdio_int_handler_pci(struct qdio_irq *irq_ptr)
900 if (unlikely(irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
903 if (irq_ptr->irq_poll) {
904 if (!test_and_set_bit(QDIO_IRQ_DISABLED, &irq_ptr->poll_state))
905 irq_ptr->irq_poll(irq_ptr->cdev, irq_ptr->int_parm);
907 QDIO_PERF_STAT_INC(irq_ptr, int_discarded);
909 for_each_input_queue(irq_ptr, q, i)
910 tasklet_schedule(&q->tasklet);
913 if (!pci_out_supported(irq_ptr) || !irq_ptr->scan_threshold)
916 for_each_output_queue(irq_ptr, q, i) {
917 if (qdio_outbound_q_done(q))
919 if (need_siga_sync(q) && need_siga_sync_out_after_pci(q))
921 qdio_tasklet_schedule(q);
925 static void qdio_handle_activate_check(struct qdio_irq *irq_ptr,
926 unsigned long intparm, int cstat,
931 DBF_ERROR("%4x ACT CHECK", irq_ptr->schid.sch_no);
932 DBF_ERROR("intp :%lx", intparm);
933 DBF_ERROR("ds: %2x cs:%2x", dstat, cstat);
935 if (irq_ptr->nr_input_qs) {
936 q = irq_ptr->input_qs[0];
937 } else if (irq_ptr->nr_output_qs) {
938 q = irq_ptr->output_qs[0];
944 q->handler(q->irq_ptr->cdev, QDIO_ERROR_ACTIVATE,
945 q->nr, q->first_to_check, 0, irq_ptr->int_parm);
947 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
949 * In case of z/VM LGR (Live Guest Migration) QDIO recovery will happen.
950 * Therefore we call the LGR detection function here.
955 static void qdio_establish_handle_irq(struct qdio_irq *irq_ptr, int cstat,
958 DBF_DEV_EVENT(DBF_INFO, irq_ptr, "qest irq");
962 if (dstat & ~(DEV_STAT_DEV_END | DEV_STAT_CHN_END))
964 if (!(dstat & DEV_STAT_DEV_END))
966 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ESTABLISHED);
970 DBF_ERROR("%4x EQ:error", irq_ptr->schid.sch_no);
971 DBF_ERROR("ds: %2x cs:%2x", dstat, cstat);
972 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
975 /* qdio interrupt handler */
976 void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
979 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
980 struct subchannel_id schid;
983 if (!intparm || !irq_ptr) {
984 ccw_device_get_schid(cdev, &schid);
985 DBF_ERROR("qint:%4x", schid.sch_no);
989 if (irq_ptr->perf_stat_enabled)
990 irq_ptr->perf_stat.qdio_int++;
993 DBF_ERROR("%4x IO error", irq_ptr->schid.sch_no);
994 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
995 wake_up(&cdev->private->wait_q);
998 qdio_irq_check_sense(irq_ptr, irb);
999 cstat = irb->scsw.cmd.cstat;
1000 dstat = irb->scsw.cmd.dstat;
1002 switch (irq_ptr->state) {
1003 case QDIO_IRQ_STATE_INACTIVE:
1004 qdio_establish_handle_irq(irq_ptr, cstat, dstat);
1006 case QDIO_IRQ_STATE_CLEANUP:
1007 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1009 case QDIO_IRQ_STATE_ESTABLISHED:
1010 case QDIO_IRQ_STATE_ACTIVE:
1011 if (cstat & SCHN_STAT_PCI) {
1012 qdio_int_handler_pci(irq_ptr);
1016 qdio_handle_activate_check(irq_ptr, intparm, cstat,
1019 case QDIO_IRQ_STATE_STOPPED:
1024 wake_up(&cdev->private->wait_q);
1028 * qdio_get_ssqd_desc - get qdio subchannel description
1029 * @cdev: ccw device to get description for
1030 * @data: where to store the ssqd
1032 * Returns 0 or an error code. The results of the chsc are stored in the
1033 * specified structure.
1035 int qdio_get_ssqd_desc(struct ccw_device *cdev,
1036 struct qdio_ssqd_desc *data)
1038 struct subchannel_id schid;
1040 if (!cdev || !cdev->private)
1043 ccw_device_get_schid(cdev, &schid);
1044 DBF_EVENT("get ssqd:%4x", schid.sch_no);
1045 return qdio_setup_get_ssqd(NULL, &schid, data);
1047 EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc);
1049 static void qdio_shutdown_queues(struct qdio_irq *irq_ptr)
1054 for_each_input_queue(irq_ptr, q, i)
1055 tasklet_kill(&q->tasklet);
1057 for_each_output_queue(irq_ptr, q, i) {
1058 del_timer_sync(&q->u.out.timer);
1059 tasklet_kill(&q->tasklet);
1064 * qdio_shutdown - shut down a qdio subchannel
1065 * @cdev: associated ccw device
1066 * @how: use halt or clear to shutdown
1068 int qdio_shutdown(struct ccw_device *cdev, int how)
1070 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1071 struct subchannel_id schid;
1077 WARN_ON_ONCE(irqs_disabled());
1078 ccw_device_get_schid(cdev, &schid);
1079 DBF_EVENT("qshutdown:%4x", schid.sch_no);
1081 mutex_lock(&irq_ptr->setup_mutex);
1083 * Subchannel was already shot down. We cannot prevent being called
1084 * twice since cio may trigger a shutdown asynchronously.
1086 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1087 mutex_unlock(&irq_ptr->setup_mutex);
1092 * Indicate that the device is going down. Scheduling the queue
1093 * tasklets is forbidden from here on.
1095 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
1097 tiqdio_remove_device(irq_ptr);
1098 qdio_shutdown_queues(irq_ptr);
1099 qdio_shutdown_debug_entries(irq_ptr);
1101 /* cleanup subchannel */
1102 spin_lock_irq(get_ccwdev_lock(cdev));
1103 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
1104 if (how & QDIO_FLAG_CLEANUP_USING_CLEAR)
1105 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
1107 /* default behaviour is halt */
1108 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
1109 spin_unlock_irq(get_ccwdev_lock(cdev));
1111 DBF_ERROR("%4x SHUTD ERR", irq_ptr->schid.sch_no);
1112 DBF_ERROR("rc:%4d", rc);
1116 wait_event_interruptible_timeout(cdev->private->wait_q,
1117 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
1118 irq_ptr->state == QDIO_IRQ_STATE_ERR,
1122 qdio_shutdown_thinint(irq_ptr);
1123 qdio_shutdown_irq(irq_ptr);
1125 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1126 mutex_unlock(&irq_ptr->setup_mutex);
1131 EXPORT_SYMBOL_GPL(qdio_shutdown);
1134 * qdio_free - free data structures for a qdio subchannel
1135 * @cdev: associated ccw device
1137 int qdio_free(struct ccw_device *cdev)
1139 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1140 struct subchannel_id schid;
1145 ccw_device_get_schid(cdev, &schid);
1146 DBF_EVENT("qfree:%4x", schid.sch_no);
1147 DBF_DEV_EVENT(DBF_ERR, irq_ptr, "dbf abandoned");
1148 mutex_lock(&irq_ptr->setup_mutex);
1150 irq_ptr->debug_area = NULL;
1151 cdev->private->qdio_data = NULL;
1152 mutex_unlock(&irq_ptr->setup_mutex);
1154 qdio_free_async_data(irq_ptr);
1155 qdio_free_queues(irq_ptr);
1156 free_page((unsigned long) irq_ptr->qdr);
1157 free_page(irq_ptr->chsc_page);
1158 free_page((unsigned long) irq_ptr);
1161 EXPORT_SYMBOL_GPL(qdio_free);
1164 * qdio_allocate - allocate qdio queues and associated data
1165 * @cdev: associated ccw device
1166 * @no_input_qs: allocate this number of Input Queues
1167 * @no_output_qs: allocate this number of Output Queues
1169 int qdio_allocate(struct ccw_device *cdev, unsigned int no_input_qs,
1170 unsigned int no_output_qs)
1172 struct subchannel_id schid;
1173 struct qdio_irq *irq_ptr;
1176 ccw_device_get_schid(cdev, &schid);
1177 DBF_EVENT("qallocate:%4x", schid.sch_no);
1179 if (no_input_qs > QDIO_MAX_QUEUES_PER_IRQ ||
1180 no_output_qs > QDIO_MAX_QUEUES_PER_IRQ)
1183 /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */
1184 irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1188 irq_ptr->cdev = cdev;
1189 mutex_init(&irq_ptr->setup_mutex);
1190 if (qdio_allocate_dbf(irq_ptr))
1193 DBF_DEV_EVENT(DBF_ERR, irq_ptr, "alloc niq:%1u noq:%1u", no_input_qs,
1197 * Allocate a page for the chsc calls in qdio_establish.
1198 * Must be pre-allocated since a zfcp recovery will call
1199 * qdio_establish. In case of low memory and swap on a zfcp disk
1200 * we may not be able to allocate memory otherwise.
1202 irq_ptr->chsc_page = get_zeroed_page(GFP_KERNEL);
1203 if (!irq_ptr->chsc_page)
1206 /* qdr is used in ccw1.cda which is u32 */
1207 irq_ptr->qdr = (struct qdr *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1211 rc = qdio_allocate_qs(irq_ptr, no_input_qs, no_output_qs);
1215 INIT_LIST_HEAD(&irq_ptr->entry);
1216 cdev->private->qdio_data = irq_ptr;
1217 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1221 free_page((unsigned long) irq_ptr->qdr);
1223 free_page(irq_ptr->chsc_page);
1226 free_page((unsigned long) irq_ptr);
1229 EXPORT_SYMBOL_GPL(qdio_allocate);
1231 static void qdio_detect_hsicq(struct qdio_irq *irq_ptr)
1233 struct qdio_q *q = irq_ptr->input_qs[0];
1236 if (irq_ptr->nr_input_qs > 1 && queue_type(q) == QDIO_IQDIO_QFMT)
1239 for_each_output_queue(irq_ptr, q, i) {
1241 if (multicast_outbound(q))
1243 if (qdio_enable_async_operation(&q->u.out) < 0) {
1248 qdio_disable_async_operation(&q->u.out);
1250 DBF_EVENT("use_cq:%d", use_cq);
1253 static void qdio_trace_init_data(struct qdio_irq *irq,
1254 struct qdio_initialize *data)
1256 DBF_DEV_EVENT(DBF_ERR, irq, "qfmt:%1u", data->q_format);
1257 DBF_DEV_HEX(irq, data->adapter_name, 8, DBF_ERR);
1258 DBF_DEV_EVENT(DBF_ERR, irq, "qpff%4x", data->qib_param_field_format);
1259 DBF_DEV_HEX(irq, &data->qib_param_field, sizeof(void *), DBF_ERR);
1260 DBF_DEV_HEX(irq, &data->input_slib_elements, sizeof(void *), DBF_ERR);
1261 DBF_DEV_HEX(irq, &data->output_slib_elements, sizeof(void *), DBF_ERR);
1262 DBF_DEV_EVENT(DBF_ERR, irq, "niq:%1u noq:%1u", data->no_input_qs,
1263 data->no_output_qs);
1264 DBF_DEV_HEX(irq, &data->input_handler, sizeof(void *), DBF_ERR);
1265 DBF_DEV_HEX(irq, &data->output_handler, sizeof(void *), DBF_ERR);
1266 DBF_DEV_HEX(irq, &data->int_parm, sizeof(long), DBF_ERR);
1267 DBF_DEV_HEX(irq, &data->input_sbal_addr_array, sizeof(void *), DBF_ERR);
1268 DBF_DEV_HEX(irq, &data->output_sbal_addr_array, sizeof(void *),
1273 * qdio_establish - establish queues on a qdio subchannel
1274 * @cdev: associated ccw device
1275 * @init_data: initialization data
1277 int qdio_establish(struct ccw_device *cdev,
1278 struct qdio_initialize *init_data)
1280 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1281 struct subchannel_id schid;
1284 ccw_device_get_schid(cdev, &schid);
1285 DBF_EVENT("qestablish:%4x", schid.sch_no);
1290 if (init_data->no_input_qs > irq_ptr->max_input_qs ||
1291 init_data->no_output_qs > irq_ptr->max_output_qs)
1294 if ((init_data->no_input_qs && !init_data->input_handler) ||
1295 (init_data->no_output_qs && !init_data->output_handler))
1298 if (!init_data->input_sbal_addr_array ||
1299 !init_data->output_sbal_addr_array)
1302 mutex_lock(&irq_ptr->setup_mutex);
1303 qdio_trace_init_data(irq_ptr, init_data);
1304 qdio_setup_irq(irq_ptr, init_data);
1306 rc = qdio_establish_thinint(irq_ptr);
1308 qdio_shutdown_irq(irq_ptr);
1309 mutex_unlock(&irq_ptr->setup_mutex);
1314 irq_ptr->ccw.cmd_code = irq_ptr->equeue.cmd;
1315 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1316 irq_ptr->ccw.count = irq_ptr->equeue.count;
1317 irq_ptr->ccw.cda = (u32)((addr_t)irq_ptr->qdr);
1319 spin_lock_irq(get_ccwdev_lock(cdev));
1320 ccw_device_set_options_mask(cdev, 0);
1322 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ESTABLISH, 0, 0);
1323 spin_unlock_irq(get_ccwdev_lock(cdev));
1325 DBF_ERROR("%4x est IO ERR", irq_ptr->schid.sch_no);
1326 DBF_ERROR("rc:%4x", rc);
1327 qdio_shutdown_thinint(irq_ptr);
1328 qdio_shutdown_irq(irq_ptr);
1329 mutex_unlock(&irq_ptr->setup_mutex);
1333 wait_event_interruptible_timeout(cdev->private->wait_q,
1334 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
1335 irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ);
1337 if (irq_ptr->state != QDIO_IRQ_STATE_ESTABLISHED) {
1338 mutex_unlock(&irq_ptr->setup_mutex);
1339 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1343 qdio_setup_ssqd_info(irq_ptr);
1345 qdio_detect_hsicq(irq_ptr);
1347 /* qebsm is now setup if available, initialize buffer states */
1348 qdio_init_buf_states(irq_ptr);
1350 mutex_unlock(&irq_ptr->setup_mutex);
1351 qdio_print_subchannel_info(irq_ptr);
1352 qdio_setup_debug_entries(irq_ptr);
1355 EXPORT_SYMBOL_GPL(qdio_establish);
1358 * qdio_activate - activate queues on a qdio subchannel
1359 * @cdev: associated cdev
1361 int qdio_activate(struct ccw_device *cdev)
1363 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1364 struct subchannel_id schid;
1367 ccw_device_get_schid(cdev, &schid);
1368 DBF_EVENT("qactivate:%4x", schid.sch_no);
1373 mutex_lock(&irq_ptr->setup_mutex);
1374 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1379 irq_ptr->ccw.cmd_code = irq_ptr->aqueue.cmd;
1380 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1381 irq_ptr->ccw.count = irq_ptr->aqueue.count;
1382 irq_ptr->ccw.cda = 0;
1384 spin_lock_irq(get_ccwdev_lock(cdev));
1385 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
1387 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ACTIVATE,
1388 0, DOIO_DENY_PREFETCH);
1389 spin_unlock_irq(get_ccwdev_lock(cdev));
1391 DBF_ERROR("%4x act IO ERR", irq_ptr->schid.sch_no);
1392 DBF_ERROR("rc:%4x", rc);
1396 if (is_thinint_irq(irq_ptr))
1397 tiqdio_add_device(irq_ptr);
1399 /* wait for subchannel to become active */
1402 switch (irq_ptr->state) {
1403 case QDIO_IRQ_STATE_STOPPED:
1404 case QDIO_IRQ_STATE_ERR:
1408 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
1412 mutex_unlock(&irq_ptr->setup_mutex);
1415 EXPORT_SYMBOL_GPL(qdio_activate);
1418 * handle_inbound - reset processed input buffers
1419 * @q: queue containing the buffers
1421 * @bufnr: first buffer to process
1422 * @count: how many buffers are emptied
1424 static int handle_inbound(struct qdio_q *q, unsigned int callflags,
1425 int bufnr, int count)
1429 qperf_inc(q, inbound_call);
1431 /* If any processed SBALs are returned to HW, adjust our tracking: */
1432 overlap = min_t(int, count - sub_buf(q->u.in.batch_start, bufnr),
1433 q->u.in.batch_count);
1435 q->u.in.batch_start = add_buf(q->u.in.batch_start, overlap);
1436 q->u.in.batch_count -= overlap;
1439 count = set_buf_states(q, bufnr, SLSB_CU_INPUT_EMPTY, count);
1440 atomic_add(count, &q->nr_buf_used);
1442 if (need_siga_in(q))
1443 return qdio_siga_input(q);
1449 * handle_outbound - process filled outbound buffers
1450 * @q: queue containing the buffers
1452 * @bufnr: first buffer to process
1453 * @count: how many buffers are filled
1455 static int handle_outbound(struct qdio_q *q, unsigned int callflags,
1456 unsigned int bufnr, unsigned int count)
1458 const unsigned int scan_threshold = q->irq_ptr->scan_threshold;
1459 unsigned char state = 0;
1462 qperf_inc(q, outbound_call);
1464 count = set_buf_states(q, bufnr, SLSB_CU_OUTPUT_PRIMED, count);
1465 used = atomic_add_return(count, &q->nr_buf_used);
1467 if (used == QDIO_MAX_BUFFERS_PER_Q)
1468 qperf_inc(q, outbound_queue_full);
1470 if (callflags & QDIO_FLAG_PCI_OUT) {
1471 q->u.out.pci_out_enabled = 1;
1472 qperf_inc(q, pci_request_int);
1474 q->u.out.pci_out_enabled = 0;
1476 if (queue_type(q) == QDIO_IQDIO_QFMT) {
1477 unsigned long phys_aob = 0;
1479 if (q->u.out.use_cq && count == 1)
1480 phys_aob = qdio_aob_for_buffer(&q->u.out, bufnr);
1482 rc = qdio_kick_outbound_q(q, count, phys_aob);
1483 } else if (need_siga_sync(q)) {
1484 rc = qdio_siga_sync_q(q);
1485 } else if (count < QDIO_MAX_BUFFERS_PER_Q &&
1486 get_buf_state(q, prev_buf(bufnr), &state, 0) > 0 &&
1487 state == SLSB_CU_OUTPUT_PRIMED) {
1488 /* The previous buffer is not processed yet, tack on. */
1489 qperf_inc(q, fast_requeue);
1491 rc = qdio_kick_outbound_q(q, count, 0);
1494 /* Let drivers implement their own completion scanning: */
1495 if (!scan_threshold)
1498 /* in case of SIGA errors we must process the error immediately */
1499 if (used >= scan_threshold || rc)
1500 qdio_tasklet_schedule(q);
1502 /* free the SBALs in case of no further traffic */
1503 if (!timer_pending(&q->u.out.timer) &&
1504 likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE))
1505 mod_timer(&q->u.out.timer, jiffies + HZ);
1510 * do_QDIO - process input or output buffers
1511 * @cdev: associated ccw_device for the qdio subchannel
1512 * @callflags: input or output and special flags from the program
1513 * @q_nr: queue number
1514 * @bufnr: buffer number
1515 * @count: how many buffers to process
1517 int do_QDIO(struct ccw_device *cdev, unsigned int callflags,
1518 int q_nr, unsigned int bufnr, unsigned int count)
1520 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1522 if (bufnr >= QDIO_MAX_BUFFERS_PER_Q || count > QDIO_MAX_BUFFERS_PER_Q)
1528 DBF_DEV_EVENT(DBF_INFO, irq_ptr,
1529 "do%02x b:%02x c:%02x", callflags, bufnr, count);
1531 if (irq_ptr->state != QDIO_IRQ_STATE_ACTIVE)
1535 if (callflags & QDIO_FLAG_SYNC_INPUT)
1536 return handle_inbound(irq_ptr->input_qs[q_nr],
1537 callflags, bufnr, count);
1538 else if (callflags & QDIO_FLAG_SYNC_OUTPUT)
1539 return handle_outbound(irq_ptr->output_qs[q_nr],
1540 callflags, bufnr, count);
1543 EXPORT_SYMBOL_GPL(do_QDIO);
1546 * qdio_start_irq - enable interrupt processing for the device
1547 * @cdev: associated ccw_device for the qdio subchannel
1551 * 1 - irqs not started since new data is available
1553 int qdio_start_irq(struct ccw_device *cdev)
1556 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1562 for_each_input_queue(irq_ptr, q, i)
1563 qdio_stop_polling(q);
1565 clear_bit(QDIO_IRQ_DISABLED, &irq_ptr->poll_state);
1568 * We need to check again to not lose initiative after
1569 * resetting the ACK state.
1571 if (test_nonshared_ind(irq_ptr))
1574 for_each_input_queue(irq_ptr, q, i) {
1575 if (!qdio_inbound_q_done(q, q->first_to_check))
1582 if (test_and_set_bit(QDIO_IRQ_DISABLED, &irq_ptr->poll_state))
1588 EXPORT_SYMBOL(qdio_start_irq);
1590 static int __qdio_inspect_queue(struct qdio_q *q, unsigned int *bufnr,
1591 unsigned int *error)
1593 unsigned int start = q->first_to_check;
1596 count = q->is_input_q ? qdio_inbound_q_moved(q, start) :
1597 qdio_outbound_q_moved(q, start);
1602 *error = q->qdio_error;
1604 /* for the next time */
1605 q->first_to_check = add_buf(start, count);
1611 int qdio_inspect_queue(struct ccw_device *cdev, unsigned int nr, bool is_input,
1612 unsigned int *bufnr, unsigned int *error)
1614 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1619 q = is_input ? irq_ptr->input_qs[nr] : irq_ptr->output_qs[nr];
1621 if (need_siga_sync(q))
1622 qdio_siga_sync_q(q);
1624 return __qdio_inspect_queue(q, bufnr, error);
1626 EXPORT_SYMBOL_GPL(qdio_inspect_queue);
1629 * qdio_get_next_buffers - process input buffers
1630 * @cdev: associated ccw_device for the qdio subchannel
1631 * @nr: input queue number
1632 * @bufnr: first filled buffer number
1633 * @error: buffers are in error state
1637 * = 0 - no new buffers found
1638 * > 0 - number of processed buffers
1640 int qdio_get_next_buffers(struct ccw_device *cdev, int nr, int *bufnr,
1644 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1648 q = irq_ptr->input_qs[nr];
1651 * Cannot rely on automatic sync after interrupt since queues may
1652 * also be examined without interrupt.
1654 if (need_siga_sync(q))
1655 qdio_sync_queues(q);
1657 qdio_check_outbound_pci_queues(irq_ptr);
1659 /* Note: upper-layer MUST stop processing immediately here ... */
1660 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
1663 return __qdio_inspect_queue(q, bufnr, error);
1665 EXPORT_SYMBOL(qdio_get_next_buffers);
1668 * qdio_stop_irq - disable interrupt processing for the device
1669 * @cdev: associated ccw_device for the qdio subchannel
1672 * 0 - interrupts were already disabled
1673 * 1 - interrupts successfully disabled
1675 int qdio_stop_irq(struct ccw_device *cdev)
1677 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1682 if (test_and_set_bit(QDIO_IRQ_DISABLED, &irq_ptr->poll_state))
1687 EXPORT_SYMBOL(qdio_stop_irq);
1689 static int __init init_QDIO(void)
1693 rc = qdio_debug_init();
1696 rc = qdio_setup_init();
1699 rc = qdio_thinint_init();
1711 static void __exit exit_QDIO(void)
1713 qdio_thinint_exit();
1718 module_init(init_QDIO);
1719 module_exit(exit_QDIO);