2 * Linux for s390 qdio support, buffer handling, qdio API and module support.
4 * Copyright IBM Corp. 2000, 2008
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
6 * Jan Glauber <jang@linux.vnet.ibm.com>
7 * 2.6 cio integration by Cornelia Huck <cornelia.huck@de.ibm.com>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/timer.h>
13 #include <linux/delay.h>
14 #include <linux/gfp.h>
16 #include <linux/atomic.h>
17 #include <asm/debug.h>
25 #include "qdio_debug.h"
27 MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>,"\
28 "Jan Glauber <jang@linux.vnet.ibm.com>");
29 MODULE_DESCRIPTION("QDIO base support");
30 MODULE_LICENSE("GPL");
32 static inline int do_siga_sync(unsigned long schid,
33 unsigned int out_mask, unsigned int in_mask,
36 register unsigned long __fc asm ("0") = fc;
37 register unsigned long __schid asm ("1") = schid;
38 register unsigned long out asm ("2") = out_mask;
39 register unsigned long in asm ("3") = in_mask;
47 : "d" (__fc), "d" (__schid), "d" (out), "d" (in) : "cc");
51 static inline int do_siga_input(unsigned long schid, unsigned int mask,
54 register unsigned long __fc asm ("0") = fc;
55 register unsigned long __schid asm ("1") = schid;
56 register unsigned long __mask asm ("2") = mask;
64 : "d" (__fc), "d" (__schid), "d" (__mask) : "cc");
69 * do_siga_output - perform SIGA-w/wt function
70 * @schid: subchannel id or in case of QEBSM the subchannel token
71 * @mask: which output queues to process
72 * @bb: busy bit indicator, set only if SIGA-w/wt could not access a buffer
73 * @fc: function code to perform
75 * Returns condition code.
76 * Note: For IQDC unicast queues only the highest priority queue is processed.
78 static inline int do_siga_output(unsigned long schid, unsigned long mask,
79 unsigned int *bb, unsigned int fc,
82 register unsigned long __fc asm("0") = fc;
83 register unsigned long __schid asm("1") = schid;
84 register unsigned long __mask asm("2") = mask;
85 register unsigned long __aob asm("3") = aob;
92 : "=d" (cc), "+d" (__fc), "+d" (__aob)
93 : "d" (__schid), "d" (__mask)
99 static inline int qdio_check_ccq(struct qdio_q *q, unsigned int ccq)
101 /* all done or next buffer state different */
102 if (ccq == 0 || ccq == 32)
104 /* no buffer processed */
107 /* not all buffers processed */
110 /* notify devices immediately */
111 DBF_ERROR("%4x ccq:%3d", SCH_NO(q), ccq);
116 * qdio_do_eqbs - extract buffer states for QEBSM
117 * @q: queue to manipulate
118 * @state: state of the extracted buffers
119 * @start: buffer number to start at
120 * @count: count of buffers to examine
121 * @auto_ack: automatically acknowledge buffers
123 * Returns the number of successfully extracted equal buffer states.
124 * Stops processing if a state is different from the last buffers state.
126 static int qdio_do_eqbs(struct qdio_q *q, unsigned char *state,
127 int start, int count, int auto_ack)
129 int rc, tmp_count = count, tmp_start = start, nr = q->nr, retried = 0;
130 unsigned int ccq = 0;
135 nr += q->irq_ptr->nr_input_qs;
137 ccq = do_eqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count,
139 rc = qdio_check_ccq(q, ccq);
141 return count - tmp_count;
144 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "EQBS again:%2d", ccq);
149 qperf_inc(q, eqbs_partial);
150 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "EQBS part:%02x",
153 * Retry once, if that fails bail out and process the
154 * extracted buffers before trying again.
159 return count - tmp_count;
162 DBF_ERROR("%4x EQBS ERROR", SCH_NO(q));
163 DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
164 q->handler(q->irq_ptr->cdev, QDIO_ERROR_GET_BUF_STATE,
165 q->nr, q->first_to_kick, count, q->irq_ptr->int_parm);
170 * qdio_do_sqbs - set buffer states for QEBSM
171 * @q: queue to manipulate
172 * @state: new state of the buffers
173 * @start: first buffer number to change
174 * @count: how many buffers to change
176 * Returns the number of successfully changed buffers.
177 * Does retrying until the specified count of buffer states is set or an
180 static int qdio_do_sqbs(struct qdio_q *q, unsigned char state, int start,
183 unsigned int ccq = 0;
184 int tmp_count = count, tmp_start = start;
193 nr += q->irq_ptr->nr_input_qs;
195 ccq = do_sqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count);
196 rc = qdio_check_ccq(q, ccq);
198 WARN_ON_ONCE(tmp_count);
199 return count - tmp_count;
202 if (rc == 1 || rc == 2) {
203 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "SQBS again:%2d", ccq);
204 qperf_inc(q, sqbs_partial);
208 DBF_ERROR("%4x SQBS ERROR", SCH_NO(q));
209 DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
210 q->handler(q->irq_ptr->cdev, QDIO_ERROR_SET_BUF_STATE,
211 q->nr, q->first_to_kick, count, q->irq_ptr->int_parm);
215 /* returns number of examined buffers and their common state in *state */
216 static inline int get_buf_states(struct qdio_q *q, unsigned int bufnr,
217 unsigned char *state, unsigned int count,
218 int auto_ack, int merge_pending)
220 unsigned char __state = 0;
224 return qdio_do_eqbs(q, state, bufnr, count, auto_ack);
226 for (i = 0; i < count; i++) {
228 __state = q->slsb.val[bufnr];
229 if (merge_pending && __state == SLSB_P_OUTPUT_PENDING)
230 __state = SLSB_P_OUTPUT_EMPTY;
231 } else if (merge_pending) {
232 if ((q->slsb.val[bufnr] & __state) != __state)
234 } else if (q->slsb.val[bufnr] != __state)
236 bufnr = next_buf(bufnr);
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 for (i = 0; i < count; i++) {
258 xchg(&q->slsb.val[bufnr], state);
259 bufnr = next_buf(bufnr);
264 static inline int set_buf_state(struct qdio_q *q, int bufnr,
267 return set_buf_states(q, bufnr, state, 1);
270 /* set slsb states to initial state */
271 static void qdio_init_buf_states(struct qdio_irq *irq_ptr)
276 for_each_input_queue(irq_ptr, q, i)
277 set_buf_states(q, 0, SLSB_P_INPUT_NOT_INIT,
278 QDIO_MAX_BUFFERS_PER_Q);
279 for_each_output_queue(irq_ptr, q, i)
280 set_buf_states(q, 0, SLSB_P_OUTPUT_NOT_INIT,
281 QDIO_MAX_BUFFERS_PER_Q);
284 static inline int qdio_siga_sync(struct qdio_q *q, unsigned int output,
287 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
288 unsigned int fc = QDIO_SIGA_SYNC;
291 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-s:%1d", q->nr);
292 qperf_inc(q, siga_sync);
295 schid = q->irq_ptr->sch_token;
296 fc |= QDIO_SIGA_QEBSM_FLAG;
299 cc = do_siga_sync(schid, output, input, fc);
301 DBF_ERROR("%4x SIGA-S:%2d", SCH_NO(q), cc);
302 return (cc) ? -EIO : 0;
305 static inline int qdio_siga_sync_q(struct qdio_q *q)
308 return qdio_siga_sync(q, 0, q->mask);
310 return qdio_siga_sync(q, q->mask, 0);
313 static int qdio_siga_output(struct qdio_q *q, unsigned int *busy_bit,
316 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
317 unsigned int fc = QDIO_SIGA_WRITE;
320 unsigned long laob = 0;
322 WARN_ON_ONCE(aob && ((queue_type(q) != QDIO_IQDIO_QFMT) ||
324 if (q->u.out.use_cq && aob != 0) {
325 fc = QDIO_SIGA_WRITEQ;
330 schid = q->irq_ptr->sch_token;
331 fc |= QDIO_SIGA_QEBSM_FLAG;
334 cc = do_siga_output(schid, q->mask, busy_bit, fc, laob);
336 /* hipersocket busy condition */
337 if (unlikely(*busy_bit)) {
341 start_time = get_tod_clock_fast();
344 if (get_tod_clock_fast() - start_time < QDIO_BUSY_BIT_PATIENCE)
348 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr,
349 "%4x cc2 BB1:%1d", SCH_NO(q), q->nr);
350 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "count:%u", retries);
355 static inline int qdio_siga_input(struct qdio_q *q)
357 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
358 unsigned int fc = QDIO_SIGA_READ;
361 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-r:%1d", q->nr);
362 qperf_inc(q, siga_read);
365 schid = q->irq_ptr->sch_token;
366 fc |= QDIO_SIGA_QEBSM_FLAG;
369 cc = do_siga_input(schid, q->mask, fc);
371 DBF_ERROR("%4x SIGA-R:%2d", SCH_NO(q), cc);
372 return (cc) ? -EIO : 0;
375 #define qdio_siga_sync_out(q) qdio_siga_sync(q, ~0U, 0)
376 #define qdio_siga_sync_all(q) qdio_siga_sync(q, ~0U, ~0U)
378 static inline void qdio_sync_queues(struct qdio_q *q)
380 /* PCI capable outbound queues will also be scanned so sync them too */
381 if (pci_out_supported(q))
382 qdio_siga_sync_all(q);
387 int debug_get_buf_state(struct qdio_q *q, unsigned int bufnr,
388 unsigned char *state)
390 if (need_siga_sync(q))
392 return get_buf_states(q, bufnr, state, 1, 0, 0);
395 static inline void qdio_stop_polling(struct qdio_q *q)
397 if (!q->u.in.polling)
401 qperf_inc(q, stop_polling);
403 /* show the card that we are not polling anymore */
405 set_buf_states(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT,
407 q->u.in.ack_count = 0;
409 set_buf_state(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT);
412 static inline void account_sbals(struct qdio_q *q, unsigned int count)
416 q->q_stats.nr_sbal_total += count;
417 if (count == QDIO_MAX_BUFFERS_MASK) {
418 q->q_stats.nr_sbals[7]++;
422 q->q_stats.nr_sbals[pos]++;
425 static void process_buffer_error(struct qdio_q *q, int count)
427 unsigned char state = (q->is_input_q) ? SLSB_P_INPUT_NOT_INIT :
428 SLSB_P_OUTPUT_NOT_INIT;
430 q->qdio_error = QDIO_ERROR_SLSB_STATE;
432 /* special handling for no target buffer empty */
433 if ((!q->is_input_q &&
434 (q->sbal[q->first_to_check]->element[15].sflags) == 0x10)) {
435 qperf_inc(q, target_full);
436 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "OUTFULL FTC:%02x",
441 DBF_ERROR("%4x BUF ERROR", SCH_NO(q));
442 DBF_ERROR((q->is_input_q) ? "IN:%2d" : "OUT:%2d", q->nr);
443 DBF_ERROR("FTC:%3d C:%3d", q->first_to_check, count);
444 DBF_ERROR("F14:%2x F15:%2x",
445 q->sbal[q->first_to_check]->element[14].sflags,
446 q->sbal[q->first_to_check]->element[15].sflags);
450 * Interrupts may be avoided as long as the error is present
451 * so change the buffer state immediately to avoid starvation.
453 set_buf_states(q, q->first_to_check, state, count);
456 static inline void inbound_primed(struct qdio_q *q, int count)
460 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in prim: %02x", count);
462 /* for QEBSM the ACK was already set by EQBS */
464 if (!q->u.in.polling) {
466 q->u.in.ack_count = count;
467 q->u.in.ack_start = q->first_to_check;
471 /* delete the previous ACK's */
472 set_buf_states(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT,
474 q->u.in.ack_count = count;
475 q->u.in.ack_start = q->first_to_check;
480 * ACK the newest buffer. The ACK will be removed in qdio_stop_polling
481 * or by the next inbound run.
483 new = add_buf(q->first_to_check, count - 1);
484 if (q->u.in.polling) {
485 /* reset the previous ACK but first set the new one */
486 set_buf_state(q, new, SLSB_P_INPUT_ACK);
487 set_buf_state(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT);
490 set_buf_state(q, new, SLSB_P_INPUT_ACK);
493 q->u.in.ack_start = new;
497 /* need to change ALL buffers to get more interrupts */
498 set_buf_states(q, q->first_to_check, SLSB_P_INPUT_NOT_INIT, count);
501 static int get_inbound_buffer_frontier(struct qdio_q *q)
504 unsigned char state = 0;
506 q->timestamp = get_tod_clock_fast();
509 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
512 count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
513 stop = add_buf(q->first_to_check, count);
515 if (q->first_to_check == stop)
519 * No siga sync here, as a PCI or we after a thin interrupt
520 * already sync'ed the queues.
522 count = get_buf_states(q, q->first_to_check, &state, count, 1, 0);
527 case SLSB_P_INPUT_PRIMED:
528 inbound_primed(q, count);
529 q->first_to_check = add_buf(q->first_to_check, 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);
535 case SLSB_P_INPUT_ERROR:
536 process_buffer_error(q, count);
537 q->first_to_check = add_buf(q->first_to_check, count);
538 atomic_sub(count, &q->nr_buf_used);
539 if (q->irq_ptr->perf_stat_enabled)
540 account_sbals_error(q, 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");
553 return q->first_to_check;
556 static int qdio_inbound_q_moved(struct qdio_q *q)
560 bufnr = get_inbound_buffer_frontier(q);
562 if (bufnr != q->last_move) {
563 q->last_move = bufnr;
564 if (!is_thinint_irq(q->irq_ptr) && MACHINE_IS_LPAR)
565 q->u.in.timestamp = get_tod_clock();
571 static inline int qdio_inbound_q_done(struct qdio_q *q)
573 unsigned char state = 0;
575 if (!atomic_read(&q->nr_buf_used))
578 if (need_siga_sync(q))
580 get_buf_state(q, q->first_to_check, &state, 0);
582 if (state == SLSB_P_INPUT_PRIMED || state == SLSB_P_INPUT_ERROR)
583 /* more work coming */
586 if (is_thinint_irq(q->irq_ptr))
589 /* don't poll under z/VM */
594 * At this point we know, that inbound first_to_check
595 * has (probably) not moved (see qdio_inbound_processing).
597 if (get_tod_clock_fast() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) {
598 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in done:%02x",
605 static inline int contains_aobs(struct qdio_q *q)
607 return !q->is_input_q && q->u.out.use_cq;
610 static inline void qdio_handle_aobs(struct qdio_q *q, int start, int count)
612 unsigned char state = 0;
615 if (!contains_aobs(q))
618 for (j = 0; j < count; ++j) {
619 get_buf_state(q, b, &state, 0);
620 if (state == SLSB_P_OUTPUT_PENDING) {
621 struct qaob *aob = q->u.out.aobs[b];
625 q->u.out.sbal_state[b].flags |=
626 QDIO_OUTBUF_STATE_FLAG_PENDING;
627 q->u.out.aobs[b] = NULL;
628 } else if (state == SLSB_P_OUTPUT_EMPTY) {
629 q->u.out.sbal_state[b].aob = NULL;
635 static inline unsigned long qdio_aob_for_buffer(struct qdio_output_q *q,
638 unsigned long phys_aob = 0;
643 if (!q->aobs[bufnr]) {
644 struct qaob *aob = qdio_allocate_aob();
645 q->aobs[bufnr] = aob;
647 if (q->aobs[bufnr]) {
648 q->sbal_state[bufnr].flags = QDIO_OUTBUF_STATE_FLAG_NONE;
649 q->sbal_state[bufnr].aob = q->aobs[bufnr];
650 q->aobs[bufnr]->user1 = (u64) q->sbal_state[bufnr].user;
651 phys_aob = virt_to_phys(q->aobs[bufnr]);
652 WARN_ON_ONCE(phys_aob & 0xFF);
659 static void qdio_kick_handler(struct qdio_q *q)
661 int start = q->first_to_kick;
662 int end = q->first_to_check;
665 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
668 count = sub_buf(end, start);
671 qperf_inc(q, inbound_handler);
672 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "kih s:%02x c:%02x", start, count);
674 qperf_inc(q, outbound_handler);
675 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "koh: s:%02x c:%02x",
679 qdio_handle_aobs(q, start, count);
681 q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr, start, count,
682 q->irq_ptr->int_parm);
684 /* for the next time */
685 q->first_to_kick = end;
689 static inline int qdio_tasklet_schedule(struct qdio_q *q)
691 if (likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE)) {
692 tasklet_schedule(&q->tasklet);
698 static void __qdio_inbound_processing(struct qdio_q *q)
700 qperf_inc(q, tasklet_inbound);
702 if (!qdio_inbound_q_moved(q))
705 qdio_kick_handler(q);
707 if (!qdio_inbound_q_done(q)) {
708 /* means poll time is not yet over */
709 qperf_inc(q, tasklet_inbound_resched);
710 if (!qdio_tasklet_schedule(q))
714 qdio_stop_polling(q);
716 * We need to check again to not lose initiative after
717 * resetting the ACK state.
719 if (!qdio_inbound_q_done(q)) {
720 qperf_inc(q, tasklet_inbound_resched2);
721 qdio_tasklet_schedule(q);
725 void qdio_inbound_processing(unsigned long data)
727 struct qdio_q *q = (struct qdio_q *)data;
728 __qdio_inbound_processing(q);
731 static int get_outbound_buffer_frontier(struct qdio_q *q)
734 unsigned char state = 0;
736 q->timestamp = get_tod_clock_fast();
738 if (need_siga_sync(q))
739 if (((queue_type(q) != QDIO_IQDIO_QFMT) &&
740 !pci_out_supported(q)) ||
741 (queue_type(q) == QDIO_IQDIO_QFMT &&
742 multicast_outbound(q)))
746 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
749 count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
750 stop = add_buf(q->first_to_check, count);
751 if (q->first_to_check == stop)
754 count = get_buf_states(q, q->first_to_check, &state, count, 0, 1);
759 case SLSB_P_OUTPUT_EMPTY:
760 /* the adapter got it */
761 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr,
762 "out empty:%1d %02x", q->nr, count);
764 atomic_sub(count, &q->nr_buf_used);
765 q->first_to_check = add_buf(q->first_to_check, count);
766 if (q->irq_ptr->perf_stat_enabled)
767 account_sbals(q, count);
770 case SLSB_P_OUTPUT_ERROR:
771 process_buffer_error(q, count);
772 q->first_to_check = add_buf(q->first_to_check, count);
773 atomic_sub(count, &q->nr_buf_used);
774 if (q->irq_ptr->perf_stat_enabled)
775 account_sbals_error(q, count);
777 case SLSB_CU_OUTPUT_PRIMED:
778 /* the adapter has not fetched the output yet */
779 if (q->irq_ptr->perf_stat_enabled)
780 q->q_stats.nr_sbal_nop++;
781 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out primed:%1d",
784 case SLSB_P_OUTPUT_NOT_INIT:
785 case SLSB_P_OUTPUT_HALTED:
792 return q->first_to_check;
795 /* all buffers processed? */
796 static inline int qdio_outbound_q_done(struct qdio_q *q)
798 return atomic_read(&q->nr_buf_used) == 0;
801 static inline int qdio_outbound_q_moved(struct qdio_q *q)
805 bufnr = get_outbound_buffer_frontier(q);
807 if (bufnr != q->last_move) {
808 q->last_move = bufnr;
809 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out moved:%1d", q->nr);
815 static int qdio_kick_outbound_q(struct qdio_q *q, unsigned long aob)
818 unsigned int busy_bit;
820 if (!need_siga_out(q))
823 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w:%1d", q->nr);
825 qperf_inc(q, siga_write);
827 cc = qdio_siga_output(q, &busy_bit, aob);
833 while (++retries < QDIO_BUSY_BIT_RETRIES) {
834 mdelay(QDIO_BUSY_BIT_RETRY_DELAY);
837 DBF_ERROR("%4x cc2 BBC:%1d", SCH_NO(q), q->nr);
840 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w cc2:%1d", q->nr);
846 DBF_ERROR("%4x SIGA-W:%1d", SCH_NO(q), cc);
851 DBF_ERROR("%4x cc2 BB2:%1d", SCH_NO(q), q->nr);
852 DBF_ERROR("count:%u", retries);
857 static void __qdio_outbound_processing(struct qdio_q *q)
859 qperf_inc(q, tasklet_outbound);
860 WARN_ON_ONCE(atomic_read(&q->nr_buf_used) < 0);
862 if (qdio_outbound_q_moved(q))
863 qdio_kick_handler(q);
865 if (queue_type(q) == QDIO_ZFCP_QFMT)
866 if (!pci_out_supported(q) && !qdio_outbound_q_done(q))
869 if (q->u.out.pci_out_enabled)
873 * Now we know that queue type is either qeth without pci enabled
874 * or HiperSockets. Make sure buffer switch from PRIMED to EMPTY
875 * is noticed and outbound_handler is called after some time.
877 if (qdio_outbound_q_done(q))
878 del_timer_sync(&q->u.out.timer);
880 if (!timer_pending(&q->u.out.timer) &&
881 likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE))
882 mod_timer(&q->u.out.timer, jiffies + 10 * HZ);
886 qdio_tasklet_schedule(q);
889 /* outbound tasklet */
890 void qdio_outbound_processing(unsigned long data)
892 struct qdio_q *q = (struct qdio_q *)data;
893 __qdio_outbound_processing(q);
896 void qdio_outbound_timer(unsigned long data)
898 struct qdio_q *q = (struct qdio_q *)data;
900 qdio_tasklet_schedule(q);
903 static inline void qdio_check_outbound_after_thinint(struct qdio_q *q)
908 if (!pci_out_supported(q))
911 for_each_output_queue(q->irq_ptr, out, i)
912 if (!qdio_outbound_q_done(out))
913 qdio_tasklet_schedule(out);
916 static void __tiqdio_inbound_processing(struct qdio_q *q)
918 qperf_inc(q, tasklet_inbound);
919 if (need_siga_sync(q) && need_siga_sync_after_ai(q))
923 * The interrupt could be caused by a PCI request. Check the
924 * PCI capable outbound queues.
926 qdio_check_outbound_after_thinint(q);
928 if (!qdio_inbound_q_moved(q))
931 qdio_kick_handler(q);
933 if (!qdio_inbound_q_done(q)) {
934 qperf_inc(q, tasklet_inbound_resched);
935 if (!qdio_tasklet_schedule(q))
939 qdio_stop_polling(q);
941 * We need to check again to not lose initiative after
942 * resetting the ACK state.
944 if (!qdio_inbound_q_done(q)) {
945 qperf_inc(q, tasklet_inbound_resched2);
946 qdio_tasklet_schedule(q);
950 void tiqdio_inbound_processing(unsigned long data)
952 struct qdio_q *q = (struct qdio_q *)data;
953 __tiqdio_inbound_processing(q);
956 static inline void qdio_set_state(struct qdio_irq *irq_ptr,
957 enum qdio_irq_states state)
959 DBF_DEV_EVENT(DBF_INFO, irq_ptr, "newstate: %1d", state);
961 irq_ptr->state = state;
965 static void qdio_irq_check_sense(struct qdio_irq *irq_ptr, struct irb *irb)
967 if (irb->esw.esw0.erw.cons) {
968 DBF_ERROR("%4x sense:", irq_ptr->schid.sch_no);
969 DBF_ERROR_HEX(irb, 64);
970 DBF_ERROR_HEX(irb->ecw, 64);
974 /* PCI interrupt handler */
975 static void qdio_int_handler_pci(struct qdio_irq *irq_ptr)
980 if (unlikely(irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
983 for_each_input_queue(irq_ptr, q, i) {
984 if (q->u.in.queue_start_poll) {
985 /* skip if polling is enabled or already in work */
986 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
987 &q->u.in.queue_irq_state)) {
988 qperf_inc(q, int_discarded);
991 q->u.in.queue_start_poll(q->irq_ptr->cdev, q->nr,
992 q->irq_ptr->int_parm);
994 tasklet_schedule(&q->tasklet);
998 if (!(irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED))
1001 for_each_output_queue(irq_ptr, q, i) {
1002 if (qdio_outbound_q_done(q))
1004 if (need_siga_sync(q) && need_siga_sync_out_after_pci(q))
1005 qdio_siga_sync_q(q);
1006 qdio_tasklet_schedule(q);
1010 static void qdio_handle_activate_check(struct ccw_device *cdev,
1011 unsigned long intparm, int cstat, int dstat)
1013 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1017 DBF_ERROR("%4x ACT CHECK", irq_ptr->schid.sch_no);
1018 DBF_ERROR("intp :%lx", intparm);
1019 DBF_ERROR("ds: %2x cs:%2x", dstat, cstat);
1021 if (irq_ptr->nr_input_qs) {
1022 q = irq_ptr->input_qs[0];
1023 } else if (irq_ptr->nr_output_qs) {
1024 q = irq_ptr->output_qs[0];
1030 count = sub_buf(q->first_to_check, q->first_to_kick);
1031 q->handler(q->irq_ptr->cdev, QDIO_ERROR_ACTIVATE,
1032 q->nr, q->first_to_kick, count, irq_ptr->int_parm);
1034 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
1036 * In case of z/VM LGR (Live Guest Migration) QDIO recovery will happen.
1037 * Therefore we call the LGR detection function here.
1042 static void qdio_establish_handle_irq(struct ccw_device *cdev, int cstat,
1045 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1047 DBF_DEV_EVENT(DBF_INFO, irq_ptr, "qest irq");
1051 if (dstat & ~(DEV_STAT_DEV_END | DEV_STAT_CHN_END))
1053 if (!(dstat & DEV_STAT_DEV_END))
1055 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ESTABLISHED);
1059 DBF_ERROR("%4x EQ:error", irq_ptr->schid.sch_no);
1060 DBF_ERROR("ds: %2x cs:%2x", dstat, cstat);
1061 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
1064 /* qdio interrupt handler */
1065 void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
1068 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1069 struct subchannel_id schid;
1072 if (!intparm || !irq_ptr) {
1073 ccw_device_get_schid(cdev, &schid);
1074 DBF_ERROR("qint:%4x", schid.sch_no);
1078 if (irq_ptr->perf_stat_enabled)
1079 irq_ptr->perf_stat.qdio_int++;
1082 DBF_ERROR("%4x IO error", irq_ptr->schid.sch_no);
1083 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
1084 wake_up(&cdev->private->wait_q);
1087 qdio_irq_check_sense(irq_ptr, irb);
1088 cstat = irb->scsw.cmd.cstat;
1089 dstat = irb->scsw.cmd.dstat;
1091 switch (irq_ptr->state) {
1092 case QDIO_IRQ_STATE_INACTIVE:
1093 qdio_establish_handle_irq(cdev, cstat, dstat);
1095 case QDIO_IRQ_STATE_CLEANUP:
1096 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1098 case QDIO_IRQ_STATE_ESTABLISHED:
1099 case QDIO_IRQ_STATE_ACTIVE:
1100 if (cstat & SCHN_STAT_PCI) {
1101 qdio_int_handler_pci(irq_ptr);
1105 qdio_handle_activate_check(cdev, intparm, cstat,
1108 case QDIO_IRQ_STATE_STOPPED:
1113 wake_up(&cdev->private->wait_q);
1117 * qdio_get_ssqd_desc - get qdio subchannel description
1118 * @cdev: ccw device to get description for
1119 * @data: where to store the ssqd
1121 * Returns 0 or an error code. The results of the chsc are stored in the
1122 * specified structure.
1124 int qdio_get_ssqd_desc(struct ccw_device *cdev,
1125 struct qdio_ssqd_desc *data)
1127 struct subchannel_id schid;
1129 if (!cdev || !cdev->private)
1132 ccw_device_get_schid(cdev, &schid);
1133 DBF_EVENT("get ssqd:%4x", schid.sch_no);
1134 return qdio_setup_get_ssqd(NULL, &schid, data);
1136 EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc);
1138 static void qdio_shutdown_queues(struct ccw_device *cdev)
1140 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1144 for_each_input_queue(irq_ptr, q, i)
1145 tasklet_kill(&q->tasklet);
1147 for_each_output_queue(irq_ptr, q, i) {
1148 del_timer_sync(&q->u.out.timer);
1149 tasklet_kill(&q->tasklet);
1154 * qdio_shutdown - shut down a qdio subchannel
1155 * @cdev: associated ccw device
1156 * @how: use halt or clear to shutdown
1158 int qdio_shutdown(struct ccw_device *cdev, int how)
1160 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1161 struct subchannel_id schid;
1167 WARN_ON_ONCE(irqs_disabled());
1168 ccw_device_get_schid(cdev, &schid);
1169 DBF_EVENT("qshutdown:%4x", schid.sch_no);
1171 mutex_lock(&irq_ptr->setup_mutex);
1173 * Subchannel was already shot down. We cannot prevent being called
1174 * twice since cio may trigger a shutdown asynchronously.
1176 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1177 mutex_unlock(&irq_ptr->setup_mutex);
1182 * Indicate that the device is going down. Scheduling the queue
1183 * tasklets is forbidden from here on.
1185 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
1187 tiqdio_remove_input_queues(irq_ptr);
1188 qdio_shutdown_queues(cdev);
1189 qdio_shutdown_debug_entries(irq_ptr);
1191 /* cleanup subchannel */
1192 spin_lock_irq(get_ccwdev_lock(cdev));
1194 if (how & QDIO_FLAG_CLEANUP_USING_CLEAR)
1195 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
1197 /* default behaviour is halt */
1198 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
1200 DBF_ERROR("%4x SHUTD ERR", irq_ptr->schid.sch_no);
1201 DBF_ERROR("rc:%4d", rc);
1205 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
1206 spin_unlock_irq(get_ccwdev_lock(cdev));
1207 wait_event_interruptible_timeout(cdev->private->wait_q,
1208 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
1209 irq_ptr->state == QDIO_IRQ_STATE_ERR,
1211 spin_lock_irq(get_ccwdev_lock(cdev));
1214 qdio_shutdown_thinint(irq_ptr);
1216 /* restore interrupt handler */
1217 if ((void *)cdev->handler == (void *)qdio_int_handler)
1218 cdev->handler = irq_ptr->orig_handler;
1219 spin_unlock_irq(get_ccwdev_lock(cdev));
1221 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1222 mutex_unlock(&irq_ptr->setup_mutex);
1227 EXPORT_SYMBOL_GPL(qdio_shutdown);
1230 * qdio_free - free data structures for a qdio subchannel
1231 * @cdev: associated ccw device
1233 int qdio_free(struct ccw_device *cdev)
1235 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1236 struct subchannel_id schid;
1241 ccw_device_get_schid(cdev, &schid);
1242 DBF_EVENT("qfree:%4x", schid.sch_no);
1243 DBF_DEV_EVENT(DBF_ERR, irq_ptr, "dbf abandoned");
1244 mutex_lock(&irq_ptr->setup_mutex);
1246 irq_ptr->debug_area = NULL;
1247 cdev->private->qdio_data = NULL;
1248 mutex_unlock(&irq_ptr->setup_mutex);
1250 qdio_release_memory(irq_ptr);
1253 EXPORT_SYMBOL_GPL(qdio_free);
1256 * qdio_allocate - allocate qdio queues and associated data
1257 * @init_data: initialization data
1259 int qdio_allocate(struct qdio_initialize *init_data)
1261 struct subchannel_id schid;
1262 struct qdio_irq *irq_ptr;
1264 ccw_device_get_schid(init_data->cdev, &schid);
1265 DBF_EVENT("qallocate:%4x", schid.sch_no);
1267 if ((init_data->no_input_qs && !init_data->input_handler) ||
1268 (init_data->no_output_qs && !init_data->output_handler))
1271 if ((init_data->no_input_qs > QDIO_MAX_QUEUES_PER_IRQ) ||
1272 (init_data->no_output_qs > QDIO_MAX_QUEUES_PER_IRQ))
1275 if ((!init_data->input_sbal_addr_array) ||
1276 (!init_data->output_sbal_addr_array))
1279 /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */
1280 irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1284 mutex_init(&irq_ptr->setup_mutex);
1285 if (qdio_allocate_dbf(init_data, irq_ptr))
1289 * Allocate a page for the chsc calls in qdio_establish.
1290 * Must be pre-allocated since a zfcp recovery will call
1291 * qdio_establish. In case of low memory and swap on a zfcp disk
1292 * we may not be able to allocate memory otherwise.
1294 irq_ptr->chsc_page = get_zeroed_page(GFP_KERNEL);
1295 if (!irq_ptr->chsc_page)
1298 /* qdr is used in ccw1.cda which is u32 */
1299 irq_ptr->qdr = (struct qdr *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1303 if (qdio_allocate_qs(irq_ptr, init_data->no_input_qs,
1304 init_data->no_output_qs))
1307 init_data->cdev->private->qdio_data = irq_ptr;
1308 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1311 qdio_release_memory(irq_ptr);
1315 EXPORT_SYMBOL_GPL(qdio_allocate);
1317 static void qdio_detect_hsicq(struct qdio_irq *irq_ptr)
1319 struct qdio_q *q = irq_ptr->input_qs[0];
1322 if (irq_ptr->nr_input_qs > 1 && queue_type(q) == QDIO_IQDIO_QFMT)
1325 for_each_output_queue(irq_ptr, q, i) {
1327 if (qdio_enable_async_operation(&q->u.out) < 0) {
1332 qdio_disable_async_operation(&q->u.out);
1334 DBF_EVENT("use_cq:%d", use_cq);
1338 * qdio_establish - establish queues on a qdio subchannel
1339 * @init_data: initialization data
1341 int qdio_establish(struct qdio_initialize *init_data)
1343 struct ccw_device *cdev = init_data->cdev;
1344 struct subchannel_id schid;
1345 struct qdio_irq *irq_ptr;
1348 ccw_device_get_schid(cdev, &schid);
1349 DBF_EVENT("qestablish:%4x", schid.sch_no);
1351 irq_ptr = cdev->private->qdio_data;
1355 mutex_lock(&irq_ptr->setup_mutex);
1356 qdio_setup_irq(init_data);
1358 rc = qdio_establish_thinint(irq_ptr);
1360 mutex_unlock(&irq_ptr->setup_mutex);
1361 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1366 irq_ptr->ccw.cmd_code = irq_ptr->equeue.cmd;
1367 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1368 irq_ptr->ccw.count = irq_ptr->equeue.count;
1369 irq_ptr->ccw.cda = (u32)((addr_t)irq_ptr->qdr);
1371 spin_lock_irq(get_ccwdev_lock(cdev));
1372 ccw_device_set_options_mask(cdev, 0);
1374 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ESTABLISH, 0, 0);
1375 spin_unlock_irq(get_ccwdev_lock(cdev));
1377 DBF_ERROR("%4x est IO ERR", irq_ptr->schid.sch_no);
1378 DBF_ERROR("rc:%4x", rc);
1379 mutex_unlock(&irq_ptr->setup_mutex);
1380 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1384 wait_event_interruptible_timeout(cdev->private->wait_q,
1385 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
1386 irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ);
1388 if (irq_ptr->state != QDIO_IRQ_STATE_ESTABLISHED) {
1389 mutex_unlock(&irq_ptr->setup_mutex);
1390 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1394 qdio_setup_ssqd_info(irq_ptr);
1396 qdio_detect_hsicq(irq_ptr);
1398 /* qebsm is now setup if available, initialize buffer states */
1399 qdio_init_buf_states(irq_ptr);
1401 mutex_unlock(&irq_ptr->setup_mutex);
1402 qdio_print_subchannel_info(irq_ptr, cdev);
1403 qdio_setup_debug_entries(irq_ptr, cdev);
1406 EXPORT_SYMBOL_GPL(qdio_establish);
1409 * qdio_activate - activate queues on a qdio subchannel
1410 * @cdev: associated cdev
1412 int qdio_activate(struct ccw_device *cdev)
1414 struct subchannel_id schid;
1415 struct qdio_irq *irq_ptr;
1418 ccw_device_get_schid(cdev, &schid);
1419 DBF_EVENT("qactivate:%4x", schid.sch_no);
1421 irq_ptr = cdev->private->qdio_data;
1425 mutex_lock(&irq_ptr->setup_mutex);
1426 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1431 irq_ptr->ccw.cmd_code = irq_ptr->aqueue.cmd;
1432 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1433 irq_ptr->ccw.count = irq_ptr->aqueue.count;
1434 irq_ptr->ccw.cda = 0;
1436 spin_lock_irq(get_ccwdev_lock(cdev));
1437 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
1439 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ACTIVATE,
1440 0, DOIO_DENY_PREFETCH);
1441 spin_unlock_irq(get_ccwdev_lock(cdev));
1443 DBF_ERROR("%4x act IO ERR", irq_ptr->schid.sch_no);
1444 DBF_ERROR("rc:%4x", rc);
1448 if (is_thinint_irq(irq_ptr))
1449 tiqdio_add_input_queues(irq_ptr);
1451 /* wait for subchannel to become active */
1454 switch (irq_ptr->state) {
1455 case QDIO_IRQ_STATE_STOPPED:
1456 case QDIO_IRQ_STATE_ERR:
1460 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
1464 mutex_unlock(&irq_ptr->setup_mutex);
1467 EXPORT_SYMBOL_GPL(qdio_activate);
1469 static inline int buf_in_between(int bufnr, int start, int count)
1471 int end = add_buf(start, count);
1474 if (bufnr >= start && bufnr < end)
1480 /* wrap-around case */
1481 if ((bufnr >= start && bufnr <= QDIO_MAX_BUFFERS_PER_Q) ||
1489 * handle_inbound - reset processed input buffers
1490 * @q: queue containing the buffers
1492 * @bufnr: first buffer to process
1493 * @count: how many buffers are emptied
1495 static int handle_inbound(struct qdio_q *q, unsigned int callflags,
1496 int bufnr, int count)
1500 qperf_inc(q, inbound_call);
1502 if (!q->u.in.polling)
1505 /* protect against stop polling setting an ACK for an emptied slsb */
1506 if (count == QDIO_MAX_BUFFERS_PER_Q) {
1507 /* overwriting everything, just delete polling status */
1508 q->u.in.polling = 0;
1509 q->u.in.ack_count = 0;
1511 } else if (buf_in_between(q->u.in.ack_start, bufnr, count)) {
1513 /* partial overwrite, just update ack_start */
1514 diff = add_buf(bufnr, count);
1515 diff = sub_buf(diff, q->u.in.ack_start);
1516 q->u.in.ack_count -= diff;
1517 if (q->u.in.ack_count <= 0) {
1518 q->u.in.polling = 0;
1519 q->u.in.ack_count = 0;
1522 q->u.in.ack_start = add_buf(q->u.in.ack_start, diff);
1525 /* the only ACK will be deleted, so stop polling */
1526 q->u.in.polling = 0;
1530 count = set_buf_states(q, bufnr, SLSB_CU_INPUT_EMPTY, count);
1531 atomic_add(count, &q->nr_buf_used);
1533 if (need_siga_in(q))
1534 return qdio_siga_input(q);
1540 * handle_outbound - process filled outbound buffers
1541 * @q: queue containing the buffers
1543 * @bufnr: first buffer to process
1544 * @count: how many buffers are filled
1546 static int handle_outbound(struct qdio_q *q, unsigned int callflags,
1547 int bufnr, int count)
1549 unsigned char state = 0;
1552 qperf_inc(q, outbound_call);
1554 count = set_buf_states(q, bufnr, SLSB_CU_OUTPUT_PRIMED, count);
1555 used = atomic_add_return(count, &q->nr_buf_used);
1557 if (used == QDIO_MAX_BUFFERS_PER_Q)
1558 qperf_inc(q, outbound_queue_full);
1560 if (callflags & QDIO_FLAG_PCI_OUT) {
1561 q->u.out.pci_out_enabled = 1;
1562 qperf_inc(q, pci_request_int);
1564 q->u.out.pci_out_enabled = 0;
1566 if (queue_type(q) == QDIO_IQDIO_QFMT) {
1567 unsigned long phys_aob = 0;
1569 /* One SIGA-W per buffer required for unicast HSI */
1570 WARN_ON_ONCE(count > 1 && !multicast_outbound(q));
1572 phys_aob = qdio_aob_for_buffer(&q->u.out, bufnr);
1574 rc = qdio_kick_outbound_q(q, phys_aob);
1575 } else if (need_siga_sync(q)) {
1576 rc = qdio_siga_sync_q(q);
1578 /* try to fast requeue buffers */
1579 get_buf_state(q, prev_buf(bufnr), &state, 0);
1580 if (state != SLSB_CU_OUTPUT_PRIMED)
1581 rc = qdio_kick_outbound_q(q, 0);
1583 qperf_inc(q, fast_requeue);
1586 /* in case of SIGA errors we must process the error immediately */
1587 if (used >= q->u.out.scan_threshold || rc)
1588 qdio_tasklet_schedule(q);
1590 /* free the SBALs in case of no further traffic */
1591 if (!timer_pending(&q->u.out.timer) &&
1592 likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE))
1593 mod_timer(&q->u.out.timer, jiffies + HZ);
1598 * do_QDIO - process input or output buffers
1599 * @cdev: associated ccw_device for the qdio subchannel
1600 * @callflags: input or output and special flags from the program
1601 * @q_nr: queue number
1602 * @bufnr: buffer number
1603 * @count: how many buffers to process
1605 int do_QDIO(struct ccw_device *cdev, unsigned int callflags,
1606 int q_nr, unsigned int bufnr, unsigned int count)
1608 struct qdio_irq *irq_ptr;
1610 if (bufnr >= QDIO_MAX_BUFFERS_PER_Q || count > QDIO_MAX_BUFFERS_PER_Q)
1613 irq_ptr = cdev->private->qdio_data;
1617 DBF_DEV_EVENT(DBF_INFO, irq_ptr,
1618 "do%02x b:%02x c:%02x", callflags, bufnr, count);
1620 if (irq_ptr->state != QDIO_IRQ_STATE_ACTIVE)
1624 if (callflags & QDIO_FLAG_SYNC_INPUT)
1625 return handle_inbound(irq_ptr->input_qs[q_nr],
1626 callflags, bufnr, count);
1627 else if (callflags & QDIO_FLAG_SYNC_OUTPUT)
1628 return handle_outbound(irq_ptr->output_qs[q_nr],
1629 callflags, bufnr, count);
1632 EXPORT_SYMBOL_GPL(do_QDIO);
1635 * qdio_start_irq - process input buffers
1636 * @cdev: associated ccw_device for the qdio subchannel
1637 * @nr: input queue number
1641 * 1 - irqs not started since new data is available
1643 int qdio_start_irq(struct ccw_device *cdev, int nr)
1646 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1650 q = irq_ptr->input_qs[nr];
1652 clear_nonshared_ind(irq_ptr);
1653 qdio_stop_polling(q);
1654 clear_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state);
1657 * We need to check again to not lose initiative after
1658 * resetting the ACK state.
1660 if (test_nonshared_ind(irq_ptr))
1662 if (!qdio_inbound_q_done(q))
1667 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
1668 &q->u.in.queue_irq_state))
1674 EXPORT_SYMBOL(qdio_start_irq);
1677 * qdio_get_next_buffers - process input buffers
1678 * @cdev: associated ccw_device for the qdio subchannel
1679 * @nr: input queue number
1680 * @bufnr: first filled buffer number
1681 * @error: buffers are in error state
1685 * = 0 - no new buffers found
1686 * > 0 - number of processed buffers
1688 int qdio_get_next_buffers(struct ccw_device *cdev, int nr, int *bufnr,
1693 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1697 q = irq_ptr->input_qs[nr];
1700 * Cannot rely on automatic sync after interrupt since queues may
1701 * also be examined without interrupt.
1703 if (need_siga_sync(q))
1704 qdio_sync_queues(q);
1706 /* check the PCI capable outbound queues. */
1707 qdio_check_outbound_after_thinint(q);
1709 if (!qdio_inbound_q_moved(q))
1712 /* Note: upper-layer MUST stop processing immediately here ... */
1713 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
1716 start = q->first_to_kick;
1717 end = q->first_to_check;
1719 *error = q->qdio_error;
1721 /* for the next time */
1722 q->first_to_kick = end;
1724 return sub_buf(end, start);
1726 EXPORT_SYMBOL(qdio_get_next_buffers);
1729 * qdio_stop_irq - disable interrupt processing for the device
1730 * @cdev: associated ccw_device for the qdio subchannel
1731 * @nr: input queue number
1734 * 0 - interrupts were already disabled
1735 * 1 - interrupts successfully disabled
1737 int qdio_stop_irq(struct ccw_device *cdev, int nr)
1740 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1744 q = irq_ptr->input_qs[nr];
1746 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
1747 &q->u.in.queue_irq_state))
1752 EXPORT_SYMBOL(qdio_stop_irq);
1755 * qdio_pnso_brinfo() - perform network subchannel op #0 - bridge info.
1756 * @schid: Subchannel ID.
1757 * @cnc: Boolean Change-Notification Control
1758 * @response: Response code will be stored at this address
1759 * @cb: Callback function will be executed for each element
1760 * of the address list
1761 * @priv: Pointer passed from the caller to qdio_pnso_brinfo()
1762 * @type: Type of the address entry passed to the callback
1763 * @entry: Entry containg the address of the specified type
1764 * @priv: Pointer to pass to the callback function.
1766 * Performs "Store-network-bridging-information list" operation and calls
1767 * the callback function for every entry in the list. If "change-
1768 * notification-control" is set, further changes in the address list
1769 * will be reported via the IPA command.
1771 int qdio_pnso_brinfo(struct subchannel_id schid,
1772 int cnc, u16 *response,
1773 void (*cb)(void *priv, enum qdio_brinfo_entry_type type,
1777 struct chsc_pnso_area *rr;
1779 u32 prev_instance = 0;
1780 int isfirstblock = 1;
1783 rr = (struct chsc_pnso_area *)get_zeroed_page(GFP_KERNEL);
1787 /* on the first iteration, naihdr.resume_token will be zero */
1788 rc = chsc_pnso_brinfo(schid, rr, rr->naihdr.resume_token, cnc);
1789 if (rc != 0 && rc != -EBUSY)
1791 if (rr->response.code != 1) {
1800 size = rr->naihdr.naids;
1801 elems = (rr->response.length -
1802 sizeof(struct chsc_header) -
1803 sizeof(struct chsc_brinfo_naihdr)) /
1806 if (!isfirstblock && (rr->naihdr.instance != prev_instance)) {
1807 /* Inform the caller that they need to scrap */
1808 /* the data that was already reported via cb */
1813 prev_instance = rr->naihdr.instance;
1814 for (i = 0; i < elems; i++)
1816 case sizeof(struct qdio_brinfo_entry_l3_ipv6):
1817 (*cb)(priv, l3_ipv6_addr,
1818 &rr->entries.l3_ipv6[i]);
1820 case sizeof(struct qdio_brinfo_entry_l3_ipv4):
1821 (*cb)(priv, l3_ipv4_addr,
1822 &rr->entries.l3_ipv4[i]);
1824 case sizeof(struct qdio_brinfo_entry_l2):
1825 (*cb)(priv, l2_addr_lnid,
1826 &rr->entries.l2[i]);
1833 } while (rr->response.code == 0x0107 || /* channel busy */
1834 (rr->response.code == 1 && /* list stored */
1835 /* resume token is non-zero => list incomplete */
1836 (rr->naihdr.resume_token.t1 || rr->naihdr.resume_token.t2)));
1837 (*response) = rr->response.code;
1840 free_page((unsigned long)rr);
1843 EXPORT_SYMBOL_GPL(qdio_pnso_brinfo);
1845 static int __init init_QDIO(void)
1849 rc = qdio_debug_init();
1852 rc = qdio_setup_init();
1855 rc = tiqdio_allocate_memory();
1858 rc = tiqdio_register_thinints();
1864 tiqdio_free_memory();
1872 static void __exit exit_QDIO(void)
1874 tiqdio_unregister_thinints();
1875 tiqdio_free_memory();
1880 module_init(init_QDIO);
1881 module_exit(exit_QDIO);