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_WARN, 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_kick, 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_kick, 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 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->irq_ptr))
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_state(q, bufnr, state, 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, unsigned int start,
428 unsigned char state = (q->is_input_q) ? SLSB_P_INPUT_NOT_INIT :
429 SLSB_P_OUTPUT_NOT_INIT;
431 q->qdio_error = QDIO_ERROR_SLSB_STATE;
433 /* special handling for no target buffer empty */
434 if (queue_type(q) == QDIO_IQDIO_QFMT && !q->is_input_q &&
435 q->sbal[start]->element[15].sflags == 0x10) {
436 qperf_inc(q, target_full);
437 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "OUTFULL FTC:%02x", start);
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", start, count);
444 DBF_ERROR("F14:%2x F15:%2x",
445 q->sbal[start]->element[14].sflags,
446 q->sbal[start]->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, start, state, count);
456 static inline void inbound_primed(struct qdio_q *q, unsigned int start,
461 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in prim:%1d %02x", q->nr, count);
463 /* for QEBSM the ACK was already set by EQBS */
465 if (!q->u.in.polling) {
467 q->u.in.ack_count = count;
468 q->u.in.ack_start = start;
472 /* delete the previous ACK's */
473 set_buf_states(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT,
475 q->u.in.ack_count = count;
476 q->u.in.ack_start = start;
481 * ACK the newest buffer. The ACK will be removed in qdio_stop_polling
482 * or by the next inbound run.
484 new = add_buf(start, count - 1);
485 if (q->u.in.polling) {
486 /* reset the previous ACK but first set the new one */
487 set_buf_state(q, new, SLSB_P_INPUT_ACK);
488 set_buf_state(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT);
491 set_buf_state(q, new, SLSB_P_INPUT_ACK);
494 q->u.in.ack_start = new;
498 /* need to change ALL buffers to get more interrupts */
499 set_buf_states(q, start, SLSB_P_INPUT_NOT_INIT, count);
502 static int get_inbound_buffer_frontier(struct qdio_q *q, unsigned int start)
504 unsigned char state = 0;
507 q->timestamp = get_tod_clock_fast();
510 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
513 count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
518 * No siga sync here, as a PCI or we after a thin interrupt
519 * already sync'ed the queues.
521 count = get_buf_states(q, start, &state, count, 1, 0);
526 case SLSB_P_INPUT_PRIMED:
527 inbound_primed(q, start, count);
528 if (atomic_sub_return(count, &q->nr_buf_used) == 0)
529 qperf_inc(q, inbound_queue_full);
530 if (q->irq_ptr->perf_stat_enabled)
531 account_sbals(q, count);
533 case SLSB_P_INPUT_ERROR:
534 process_buffer_error(q, start, count);
535 if (atomic_sub_return(count, &q->nr_buf_used) == 0)
536 qperf_inc(q, inbound_queue_full);
537 if (q->irq_ptr->perf_stat_enabled)
538 account_sbals_error(q, count);
540 case SLSB_CU_INPUT_EMPTY:
541 case SLSB_P_INPUT_NOT_INIT:
542 case SLSB_P_INPUT_ACK:
543 if (q->irq_ptr->perf_stat_enabled)
544 q->q_stats.nr_sbal_nop++;
545 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in nop:%1d %#02x",
554 static int qdio_inbound_q_moved(struct qdio_q *q, unsigned int start)
558 count = get_inbound_buffer_frontier(q, start);
560 if (count && !is_thinint_irq(q->irq_ptr) && MACHINE_IS_LPAR)
561 q->u.in.timestamp = get_tod_clock();
566 static inline int qdio_inbound_q_done(struct qdio_q *q, unsigned int start)
568 unsigned char state = 0;
570 if (!atomic_read(&q->nr_buf_used))
573 if (need_siga_sync(q))
575 get_buf_state(q, start, &state, 0);
577 if (state == SLSB_P_INPUT_PRIMED || state == SLSB_P_INPUT_ERROR)
578 /* more work coming */
581 if (is_thinint_irq(q->irq_ptr))
584 /* don't poll under z/VM */
589 * At this point we know, that inbound first_to_check
590 * has (probably) not moved (see qdio_inbound_processing).
592 if (get_tod_clock_fast() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) {
593 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in done:%02x", start);
599 static inline void qdio_handle_aobs(struct qdio_q *q, int start, int count)
601 unsigned char state = 0;
604 for (j = 0; j < count; ++j) {
605 get_buf_state(q, b, &state, 0);
606 if (state == SLSB_P_OUTPUT_PENDING) {
607 struct qaob *aob = q->u.out.aobs[b];
611 q->u.out.sbal_state[b].flags |=
612 QDIO_OUTBUF_STATE_FLAG_PENDING;
613 q->u.out.aobs[b] = NULL;
619 static inline unsigned long qdio_aob_for_buffer(struct qdio_output_q *q,
622 unsigned long phys_aob = 0;
627 if (!q->aobs[bufnr]) {
628 struct qaob *aob = qdio_allocate_aob();
629 q->aobs[bufnr] = aob;
631 if (q->aobs[bufnr]) {
632 q->aobs[bufnr]->user1 = (u64) q->sbal_state[bufnr].user;
633 phys_aob = virt_to_phys(q->aobs[bufnr]);
634 WARN_ON_ONCE(phys_aob & 0xFF);
637 q->sbal_state[bufnr].flags = 0;
641 static void qdio_kick_handler(struct qdio_q *q, unsigned int count)
643 int start = q->first_to_kick;
645 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
649 qperf_inc(q, inbound_handler);
650 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "kih s:%02x c:%02x", start, count);
652 qperf_inc(q, outbound_handler);
653 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "koh: s:%02x c:%02x",
656 qdio_handle_aobs(q, start, count);
659 q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr, start, count,
660 q->irq_ptr->int_parm);
662 /* for the next time */
663 q->first_to_kick = add_buf(start, count);
667 static inline int qdio_tasklet_schedule(struct qdio_q *q)
669 if (likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE)) {
670 tasklet_schedule(&q->tasklet);
676 static void __qdio_inbound_processing(struct qdio_q *q)
678 unsigned int start = q->first_to_check;
681 qperf_inc(q, tasklet_inbound);
683 count = qdio_inbound_q_moved(q, start);
687 start = add_buf(start, count);
688 q->first_to_check = start;
689 qdio_kick_handler(q, count);
691 if (!qdio_inbound_q_done(q, start)) {
692 /* means poll time is not yet over */
693 qperf_inc(q, tasklet_inbound_resched);
694 if (!qdio_tasklet_schedule(q))
698 qdio_stop_polling(q);
700 * We need to check again to not lose initiative after
701 * resetting the ACK state.
703 if (!qdio_inbound_q_done(q, start)) {
704 qperf_inc(q, tasklet_inbound_resched2);
705 qdio_tasklet_schedule(q);
709 void qdio_inbound_processing(unsigned long data)
711 struct qdio_q *q = (struct qdio_q *)data;
712 __qdio_inbound_processing(q);
715 static int get_outbound_buffer_frontier(struct qdio_q *q, unsigned int start)
717 unsigned char state = 0;
720 q->timestamp = get_tod_clock_fast();
722 if (need_siga_sync(q))
723 if (((queue_type(q) != QDIO_IQDIO_QFMT) &&
724 !pci_out_supported(q->irq_ptr)) ||
725 (queue_type(q) == QDIO_IQDIO_QFMT &&
726 multicast_outbound(q)))
729 count = atomic_read(&q->nr_buf_used);
733 count = get_buf_states(q, start, &state, count, 0, q->u.out.use_cq);
738 case SLSB_P_OUTPUT_EMPTY:
739 case SLSB_P_OUTPUT_PENDING:
740 /* the adapter got it */
741 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr,
742 "out empty:%1d %02x", q->nr, count);
744 atomic_sub(count, &q->nr_buf_used);
745 if (q->irq_ptr->perf_stat_enabled)
746 account_sbals(q, count);
748 case SLSB_P_OUTPUT_ERROR:
749 process_buffer_error(q, start, count);
750 atomic_sub(count, &q->nr_buf_used);
751 if (q->irq_ptr->perf_stat_enabled)
752 account_sbals_error(q, count);
754 case SLSB_CU_OUTPUT_PRIMED:
755 /* the adapter has not fetched the output yet */
756 if (q->irq_ptr->perf_stat_enabled)
757 q->q_stats.nr_sbal_nop++;
758 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out primed:%1d",
761 case SLSB_P_OUTPUT_NOT_INIT:
762 case SLSB_P_OUTPUT_HALTED:
770 /* all buffers processed? */
771 static inline int qdio_outbound_q_done(struct qdio_q *q)
773 return atomic_read(&q->nr_buf_used) == 0;
776 static inline int qdio_outbound_q_moved(struct qdio_q *q, unsigned int start)
780 count = get_outbound_buffer_frontier(q, start);
783 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out moved:%1d", q->nr);
788 static int qdio_kick_outbound_q(struct qdio_q *q, unsigned long aob)
791 unsigned int busy_bit;
793 if (!need_siga_out(q))
796 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w:%1d", q->nr);
798 qperf_inc(q, siga_write);
800 cc = qdio_siga_output(q, &busy_bit, aob);
806 while (++retries < QDIO_BUSY_BIT_RETRIES) {
807 mdelay(QDIO_BUSY_BIT_RETRY_DELAY);
810 DBF_ERROR("%4x cc2 BBC:%1d", SCH_NO(q), q->nr);
813 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w cc2:%1d", q->nr);
819 DBF_ERROR("%4x SIGA-W:%1d", SCH_NO(q), cc);
824 DBF_ERROR("%4x cc2 BB2:%1d", SCH_NO(q), q->nr);
825 DBF_ERROR("count:%u", retries);
830 static void __qdio_outbound_processing(struct qdio_q *q)
832 unsigned int start = q->first_to_check;
835 qperf_inc(q, tasklet_outbound);
836 WARN_ON_ONCE(atomic_read(&q->nr_buf_used) < 0);
838 count = qdio_outbound_q_moved(q, start);
840 q->first_to_check = add_buf(start, count);
841 qdio_kick_handler(q, count);
844 if (queue_type(q) == QDIO_ZFCP_QFMT && !pci_out_supported(q->irq_ptr) &&
845 !qdio_outbound_q_done(q))
848 if (q->u.out.pci_out_enabled)
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.
856 if (qdio_outbound_q_done(q))
857 del_timer_sync(&q->u.out.timer);
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);
865 qdio_tasklet_schedule(q);
868 /* outbound tasklet */
869 void qdio_outbound_processing(unsigned long data)
871 struct qdio_q *q = (struct qdio_q *)data;
872 __qdio_outbound_processing(q);
875 void qdio_outbound_timer(struct timer_list *t)
877 struct qdio_q *q = from_timer(q, t, u.out.timer);
879 qdio_tasklet_schedule(q);
882 static inline void qdio_check_outbound_pci_queues(struct qdio_irq *irq)
887 if (!pci_out_supported(irq))
890 for_each_output_queue(irq, out, i)
891 if (!qdio_outbound_q_done(out))
892 qdio_tasklet_schedule(out);
895 static void __tiqdio_inbound_processing(struct qdio_q *q)
897 unsigned int start = q->first_to_check;
900 qperf_inc(q, tasklet_inbound);
901 if (need_siga_sync(q) && need_siga_sync_after_ai(q))
904 /* The interrupt could be caused by a PCI request: */
905 qdio_check_outbound_pci_queues(q->irq_ptr);
907 count = qdio_inbound_q_moved(q, start);
911 start = add_buf(start, count);
912 q->first_to_check = start;
913 qdio_kick_handler(q, count);
915 if (!qdio_inbound_q_done(q, start)) {
916 qperf_inc(q, tasklet_inbound_resched);
917 if (!qdio_tasklet_schedule(q))
921 qdio_stop_polling(q);
923 * We need to check again to not lose initiative after
924 * resetting the ACK state.
926 if (!qdio_inbound_q_done(q, start)) {
927 qperf_inc(q, tasklet_inbound_resched2);
928 qdio_tasklet_schedule(q);
932 void tiqdio_inbound_processing(unsigned long data)
934 struct qdio_q *q = (struct qdio_q *)data;
935 __tiqdio_inbound_processing(q);
938 static inline void qdio_set_state(struct qdio_irq *irq_ptr,
939 enum qdio_irq_states state)
941 DBF_DEV_EVENT(DBF_INFO, irq_ptr, "newstate: %1d", state);
943 irq_ptr->state = state;
947 static void qdio_irq_check_sense(struct qdio_irq *irq_ptr, struct irb *irb)
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);
956 /* PCI interrupt handler */
957 static void qdio_int_handler_pci(struct qdio_irq *irq_ptr)
962 if (unlikely(irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
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);
973 q->u.in.queue_start_poll(q->irq_ptr->cdev, q->nr,
974 q->irq_ptr->int_parm);
976 tasklet_schedule(&q->tasklet);
980 if (!pci_out_supported(irq_ptr))
983 for_each_output_queue(irq_ptr, q, i) {
984 if (qdio_outbound_q_done(q))
986 if (need_siga_sync(q) && need_siga_sync_out_after_pci(q))
988 qdio_tasklet_schedule(q);
992 static void qdio_handle_activate_check(struct ccw_device *cdev,
993 unsigned long intparm, int cstat, int dstat)
995 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
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);
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];
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);
1016 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
1018 * In case of z/VM LGR (Live Guest Migration) QDIO recovery will happen.
1019 * Therefore we call the LGR detection function here.
1024 static void qdio_establish_handle_irq(struct ccw_device *cdev, int cstat,
1027 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1029 DBF_DEV_EVENT(DBF_INFO, irq_ptr, "qest irq");
1033 if (dstat & ~(DEV_STAT_DEV_END | DEV_STAT_CHN_END))
1035 if (!(dstat & DEV_STAT_DEV_END))
1037 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ESTABLISHED);
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);
1046 /* qdio interrupt handler */
1047 void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
1050 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1051 struct subchannel_id schid;
1054 if (!intparm || !irq_ptr) {
1055 ccw_device_get_schid(cdev, &schid);
1056 DBF_ERROR("qint:%4x", schid.sch_no);
1060 if (irq_ptr->perf_stat_enabled)
1061 irq_ptr->perf_stat.qdio_int++;
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);
1069 qdio_irq_check_sense(irq_ptr, irb);
1070 cstat = irb->scsw.cmd.cstat;
1071 dstat = irb->scsw.cmd.dstat;
1073 switch (irq_ptr->state) {
1074 case QDIO_IRQ_STATE_INACTIVE:
1075 qdio_establish_handle_irq(cdev, cstat, dstat);
1077 case QDIO_IRQ_STATE_CLEANUP:
1078 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
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);
1087 qdio_handle_activate_check(cdev, intparm, cstat,
1090 case QDIO_IRQ_STATE_STOPPED:
1095 wake_up(&cdev->private->wait_q);
1099 * qdio_get_ssqd_desc - get qdio subchannel description
1100 * @cdev: ccw device to get description for
1101 * @data: where to store the ssqd
1103 * Returns 0 or an error code. The results of the chsc are stored in the
1104 * specified structure.
1106 int qdio_get_ssqd_desc(struct ccw_device *cdev,
1107 struct qdio_ssqd_desc *data)
1109 struct subchannel_id schid;
1111 if (!cdev || !cdev->private)
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);
1118 EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc);
1120 static void qdio_shutdown_queues(struct ccw_device *cdev)
1122 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1126 for_each_input_queue(irq_ptr, q, i)
1127 tasklet_kill(&q->tasklet);
1129 for_each_output_queue(irq_ptr, q, i) {
1130 del_timer_sync(&q->u.out.timer);
1131 tasklet_kill(&q->tasklet);
1136 * qdio_shutdown - shut down a qdio subchannel
1137 * @cdev: associated ccw device
1138 * @how: use halt or clear to shutdown
1140 int qdio_shutdown(struct ccw_device *cdev, int how)
1142 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1143 struct subchannel_id schid;
1149 WARN_ON_ONCE(irqs_disabled());
1150 ccw_device_get_schid(cdev, &schid);
1151 DBF_EVENT("qshutdown:%4x", schid.sch_no);
1153 mutex_lock(&irq_ptr->setup_mutex);
1155 * Subchannel was already shot down. We cannot prevent being called
1156 * twice since cio may trigger a shutdown asynchronously.
1158 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1159 mutex_unlock(&irq_ptr->setup_mutex);
1164 * Indicate that the device is going down. Scheduling the queue
1165 * tasklets is forbidden from here on.
1167 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
1169 tiqdio_remove_input_queues(irq_ptr);
1170 qdio_shutdown_queues(cdev);
1171 qdio_shutdown_debug_entries(irq_ptr);
1173 /* cleanup subchannel */
1174 spin_lock_irq(get_ccwdev_lock(cdev));
1176 if (how & QDIO_FLAG_CLEANUP_USING_CLEAR)
1177 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
1179 /* default behaviour is halt */
1180 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
1182 DBF_ERROR("%4x SHUTD ERR", irq_ptr->schid.sch_no);
1183 DBF_ERROR("rc:%4d", rc);
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,
1193 spin_lock_irq(get_ccwdev_lock(cdev));
1196 qdio_shutdown_thinint(irq_ptr);
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;
1203 spin_unlock_irq(get_ccwdev_lock(cdev));
1205 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1206 mutex_unlock(&irq_ptr->setup_mutex);
1211 EXPORT_SYMBOL_GPL(qdio_shutdown);
1214 * qdio_free - free data structures for a qdio subchannel
1215 * @cdev: associated ccw device
1217 int qdio_free(struct ccw_device *cdev)
1219 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1220 struct subchannel_id schid;
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);
1230 irq_ptr->debug_area = NULL;
1231 cdev->private->qdio_data = NULL;
1232 mutex_unlock(&irq_ptr->setup_mutex);
1234 qdio_release_memory(irq_ptr);
1237 EXPORT_SYMBOL_GPL(qdio_free);
1240 * qdio_allocate - allocate qdio queues and associated data
1241 * @init_data: initialization data
1243 int qdio_allocate(struct qdio_initialize *init_data)
1245 struct subchannel_id schid;
1246 struct qdio_irq *irq_ptr;
1248 ccw_device_get_schid(init_data->cdev, &schid);
1249 DBF_EVENT("qallocate:%4x", schid.sch_no);
1251 if ((init_data->no_input_qs && !init_data->input_handler) ||
1252 (init_data->no_output_qs && !init_data->output_handler))
1255 if ((init_data->no_input_qs > QDIO_MAX_QUEUES_PER_IRQ) ||
1256 (init_data->no_output_qs > QDIO_MAX_QUEUES_PER_IRQ))
1259 if ((!init_data->input_sbal_addr_array) ||
1260 (!init_data->output_sbal_addr_array))
1263 /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */
1264 irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1268 mutex_init(&irq_ptr->setup_mutex);
1269 if (qdio_allocate_dbf(init_data, irq_ptr))
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.
1278 irq_ptr->chsc_page = get_zeroed_page(GFP_KERNEL);
1279 if (!irq_ptr->chsc_page)
1282 /* qdr is used in ccw1.cda which is u32 */
1283 irq_ptr->qdr = (struct qdr *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1287 if (qdio_allocate_qs(irq_ptr, init_data->no_input_qs,
1288 init_data->no_output_qs))
1291 init_data->cdev->private->qdio_data = irq_ptr;
1292 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1295 qdio_release_memory(irq_ptr);
1299 EXPORT_SYMBOL_GPL(qdio_allocate);
1301 static void qdio_detect_hsicq(struct qdio_irq *irq_ptr)
1303 struct qdio_q *q = irq_ptr->input_qs[0];
1306 if (irq_ptr->nr_input_qs > 1 && queue_type(q) == QDIO_IQDIO_QFMT)
1309 for_each_output_queue(irq_ptr, q, i) {
1311 if (qdio_enable_async_operation(&q->u.out) < 0) {
1316 qdio_disable_async_operation(&q->u.out);
1318 DBF_EVENT("use_cq:%d", use_cq);
1322 * qdio_establish - establish queues on a qdio subchannel
1323 * @init_data: initialization data
1325 int qdio_establish(struct qdio_initialize *init_data)
1327 struct ccw_device *cdev = init_data->cdev;
1328 struct subchannel_id schid;
1329 struct qdio_irq *irq_ptr;
1332 ccw_device_get_schid(cdev, &schid);
1333 DBF_EVENT("qestablish:%4x", schid.sch_no);
1335 irq_ptr = cdev->private->qdio_data;
1339 mutex_lock(&irq_ptr->setup_mutex);
1340 qdio_setup_irq(init_data);
1342 rc = qdio_establish_thinint(irq_ptr);
1344 mutex_unlock(&irq_ptr->setup_mutex);
1345 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1350 irq_ptr->ccw.cmd_code = irq_ptr->equeue.cmd;
1351 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1352 irq_ptr->ccw.count = irq_ptr->equeue.count;
1353 irq_ptr->ccw.cda = (u32)((addr_t)irq_ptr->qdr);
1355 spin_lock_irq(get_ccwdev_lock(cdev));
1356 ccw_device_set_options_mask(cdev, 0);
1358 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ESTABLISH, 0, 0);
1359 spin_unlock_irq(get_ccwdev_lock(cdev));
1361 DBF_ERROR("%4x est IO ERR", irq_ptr->schid.sch_no);
1362 DBF_ERROR("rc:%4x", rc);
1363 mutex_unlock(&irq_ptr->setup_mutex);
1364 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1368 wait_event_interruptible_timeout(cdev->private->wait_q,
1369 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
1370 irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ);
1372 if (irq_ptr->state != QDIO_IRQ_STATE_ESTABLISHED) {
1373 mutex_unlock(&irq_ptr->setup_mutex);
1374 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1378 qdio_setup_ssqd_info(irq_ptr);
1380 qdio_detect_hsicq(irq_ptr);
1382 /* qebsm is now setup if available, initialize buffer states */
1383 qdio_init_buf_states(irq_ptr);
1385 mutex_unlock(&irq_ptr->setup_mutex);
1386 qdio_print_subchannel_info(irq_ptr, cdev);
1387 qdio_setup_debug_entries(irq_ptr, cdev);
1390 EXPORT_SYMBOL_GPL(qdio_establish);
1393 * qdio_activate - activate queues on a qdio subchannel
1394 * @cdev: associated cdev
1396 int qdio_activate(struct ccw_device *cdev)
1398 struct subchannel_id schid;
1399 struct qdio_irq *irq_ptr;
1402 ccw_device_get_schid(cdev, &schid);
1403 DBF_EVENT("qactivate:%4x", schid.sch_no);
1405 irq_ptr = cdev->private->qdio_data;
1409 mutex_lock(&irq_ptr->setup_mutex);
1410 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1415 irq_ptr->ccw.cmd_code = irq_ptr->aqueue.cmd;
1416 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1417 irq_ptr->ccw.count = irq_ptr->aqueue.count;
1418 irq_ptr->ccw.cda = 0;
1420 spin_lock_irq(get_ccwdev_lock(cdev));
1421 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
1423 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ACTIVATE,
1424 0, DOIO_DENY_PREFETCH);
1425 spin_unlock_irq(get_ccwdev_lock(cdev));
1427 DBF_ERROR("%4x act IO ERR", irq_ptr->schid.sch_no);
1428 DBF_ERROR("rc:%4x", rc);
1432 if (is_thinint_irq(irq_ptr))
1433 tiqdio_add_input_queues(irq_ptr);
1435 /* wait for subchannel to become active */
1438 switch (irq_ptr->state) {
1439 case QDIO_IRQ_STATE_STOPPED:
1440 case QDIO_IRQ_STATE_ERR:
1444 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
1448 mutex_unlock(&irq_ptr->setup_mutex);
1451 EXPORT_SYMBOL_GPL(qdio_activate);
1453 static inline int buf_in_between(int bufnr, int start, int count)
1455 int end = add_buf(start, count);
1458 if (bufnr >= start && bufnr < end)
1464 /* wrap-around case */
1465 if ((bufnr >= start && bufnr <= QDIO_MAX_BUFFERS_PER_Q) ||
1473 * handle_inbound - reset processed input buffers
1474 * @q: queue containing the buffers
1476 * @bufnr: first buffer to process
1477 * @count: how many buffers are emptied
1479 static int handle_inbound(struct qdio_q *q, unsigned int callflags,
1480 int bufnr, int count)
1484 qperf_inc(q, inbound_call);
1486 if (!q->u.in.polling)
1489 /* protect against stop polling setting an ACK for an emptied slsb */
1490 if (count == QDIO_MAX_BUFFERS_PER_Q) {
1491 /* overwriting everything, just delete polling status */
1492 q->u.in.polling = 0;
1493 q->u.in.ack_count = 0;
1495 } else if (buf_in_between(q->u.in.ack_start, bufnr, count)) {
1497 /* partial overwrite, just update ack_start */
1498 diff = add_buf(bufnr, count);
1499 diff = sub_buf(diff, q->u.in.ack_start);
1500 q->u.in.ack_count -= diff;
1501 if (q->u.in.ack_count <= 0) {
1502 q->u.in.polling = 0;
1503 q->u.in.ack_count = 0;
1506 q->u.in.ack_start = add_buf(q->u.in.ack_start, diff);
1509 /* the only ACK will be deleted, so stop polling */
1510 q->u.in.polling = 0;
1514 count = set_buf_states(q, bufnr, SLSB_CU_INPUT_EMPTY, count);
1515 atomic_add(count, &q->nr_buf_used);
1517 if (need_siga_in(q))
1518 return qdio_siga_input(q);
1524 * handle_outbound - process filled outbound buffers
1525 * @q: queue containing the buffers
1527 * @bufnr: first buffer to process
1528 * @count: how many buffers are filled
1530 static int handle_outbound(struct qdio_q *q, unsigned int callflags,
1531 int bufnr, int count)
1533 unsigned char state = 0;
1536 qperf_inc(q, outbound_call);
1538 count = set_buf_states(q, bufnr, SLSB_CU_OUTPUT_PRIMED, count);
1539 used = atomic_add_return(count, &q->nr_buf_used);
1541 if (used == QDIO_MAX_BUFFERS_PER_Q)
1542 qperf_inc(q, outbound_queue_full);
1544 if (callflags & QDIO_FLAG_PCI_OUT) {
1545 q->u.out.pci_out_enabled = 1;
1546 qperf_inc(q, pci_request_int);
1548 q->u.out.pci_out_enabled = 0;
1550 if (queue_type(q) == QDIO_IQDIO_QFMT) {
1551 unsigned long phys_aob = 0;
1553 /* One SIGA-W per buffer required for unicast HSI */
1554 WARN_ON_ONCE(count > 1 && !multicast_outbound(q));
1556 phys_aob = qdio_aob_for_buffer(&q->u.out, bufnr);
1558 rc = qdio_kick_outbound_q(q, phys_aob);
1559 } else if (need_siga_sync(q)) {
1560 rc = qdio_siga_sync_q(q);
1562 /* try to fast requeue buffers */
1563 get_buf_state(q, prev_buf(bufnr), &state, 0);
1564 if (state != SLSB_CU_OUTPUT_PRIMED)
1565 rc = qdio_kick_outbound_q(q, 0);
1567 qperf_inc(q, fast_requeue);
1570 /* in case of SIGA errors we must process the error immediately */
1571 if (used >= q->u.out.scan_threshold || rc)
1572 qdio_tasklet_schedule(q);
1574 /* free the SBALs in case of no further traffic */
1575 if (!timer_pending(&q->u.out.timer) &&
1576 likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE))
1577 mod_timer(&q->u.out.timer, jiffies + HZ);
1582 * do_QDIO - process input or output buffers
1583 * @cdev: associated ccw_device for the qdio subchannel
1584 * @callflags: input or output and special flags from the program
1585 * @q_nr: queue number
1586 * @bufnr: buffer number
1587 * @count: how many buffers to process
1589 int do_QDIO(struct ccw_device *cdev, unsigned int callflags,
1590 int q_nr, unsigned int bufnr, unsigned int count)
1592 struct qdio_irq *irq_ptr;
1594 if (bufnr >= QDIO_MAX_BUFFERS_PER_Q || count > QDIO_MAX_BUFFERS_PER_Q)
1597 irq_ptr = cdev->private->qdio_data;
1601 DBF_DEV_EVENT(DBF_INFO, irq_ptr,
1602 "do%02x b:%02x c:%02x", callflags, bufnr, count);
1604 if (irq_ptr->state != QDIO_IRQ_STATE_ACTIVE)
1608 if (callflags & QDIO_FLAG_SYNC_INPUT)
1609 return handle_inbound(irq_ptr->input_qs[q_nr],
1610 callflags, bufnr, count);
1611 else if (callflags & QDIO_FLAG_SYNC_OUTPUT)
1612 return handle_outbound(irq_ptr->output_qs[q_nr],
1613 callflags, bufnr, count);
1616 EXPORT_SYMBOL_GPL(do_QDIO);
1619 * qdio_start_irq - process input buffers
1620 * @cdev: associated ccw_device for the qdio subchannel
1621 * @nr: input queue number
1625 * 1 - irqs not started since new data is available
1627 int qdio_start_irq(struct ccw_device *cdev, int nr)
1630 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1634 q = irq_ptr->input_qs[nr];
1636 clear_nonshared_ind(irq_ptr);
1637 qdio_stop_polling(q);
1638 clear_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state);
1641 * We need to check again to not lose initiative after
1642 * resetting the ACK state.
1644 if (test_nonshared_ind(irq_ptr))
1646 if (!qdio_inbound_q_done(q, q->first_to_check))
1651 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
1652 &q->u.in.queue_irq_state))
1658 EXPORT_SYMBOL(qdio_start_irq);
1661 * qdio_get_next_buffers - process input buffers
1662 * @cdev: associated ccw_device for the qdio subchannel
1663 * @nr: input queue number
1664 * @bufnr: first filled buffer number
1665 * @error: buffers are in error state
1669 * = 0 - no new buffers found
1670 * > 0 - number of processed buffers
1672 int qdio_get_next_buffers(struct ccw_device *cdev, int nr, int *bufnr,
1676 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1682 q = irq_ptr->input_qs[nr];
1683 start = q->first_to_check;
1686 * Cannot rely on automatic sync after interrupt since queues may
1687 * also be examined without interrupt.
1689 if (need_siga_sync(q))
1690 qdio_sync_queues(q);
1692 qdio_check_outbound_pci_queues(irq_ptr);
1694 count = qdio_inbound_q_moved(q, start);
1698 start = add_buf(start, count);
1699 q->first_to_check = start;
1701 /* Note: upper-layer MUST stop processing immediately here ... */
1702 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
1705 *bufnr = q->first_to_kick;
1706 *error = q->qdio_error;
1708 /* for the next time */
1709 q->first_to_kick = add_buf(q->first_to_kick, count);
1714 EXPORT_SYMBOL(qdio_get_next_buffers);
1717 * qdio_stop_irq - disable interrupt processing for the device
1718 * @cdev: associated ccw_device for the qdio subchannel
1719 * @nr: input queue number
1722 * 0 - interrupts were already disabled
1723 * 1 - interrupts successfully disabled
1725 int qdio_stop_irq(struct ccw_device *cdev, int nr)
1728 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1732 q = irq_ptr->input_qs[nr];
1734 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
1735 &q->u.in.queue_irq_state))
1740 EXPORT_SYMBOL(qdio_stop_irq);
1743 * qdio_pnso_brinfo() - perform network subchannel op #0 - bridge info.
1744 * @schid: Subchannel ID.
1745 * @cnc: Boolean Change-Notification Control
1746 * @response: Response code will be stored at this address
1747 * @cb: Callback function will be executed for each element
1748 * of the address list
1749 * @priv: Pointer to pass to the callback function.
1751 * Performs "Store-network-bridging-information list" operation and calls
1752 * the callback function for every entry in the list. If "change-
1753 * notification-control" is set, further changes in the address list
1754 * will be reported via the IPA command.
1756 int qdio_pnso_brinfo(struct subchannel_id schid,
1757 int cnc, u16 *response,
1758 void (*cb)(void *priv, enum qdio_brinfo_entry_type type,
1762 struct chsc_pnso_area *rr;
1764 u32 prev_instance = 0;
1765 int isfirstblock = 1;
1768 rr = (struct chsc_pnso_area *)get_zeroed_page(GFP_KERNEL);
1772 /* on the first iteration, naihdr.resume_token will be zero */
1773 rc = chsc_pnso_brinfo(schid, rr, rr->naihdr.resume_token, cnc);
1774 if (rc != 0 && rc != -EBUSY)
1776 if (rr->response.code != 1) {
1785 size = rr->naihdr.naids;
1786 elems = (rr->response.length -
1787 sizeof(struct chsc_header) -
1788 sizeof(struct chsc_brinfo_naihdr)) /
1791 if (!isfirstblock && (rr->naihdr.instance != prev_instance)) {
1792 /* Inform the caller that they need to scrap */
1793 /* the data that was already reported via cb */
1798 prev_instance = rr->naihdr.instance;
1799 for (i = 0; i < elems; i++)
1801 case sizeof(struct qdio_brinfo_entry_l3_ipv6):
1802 (*cb)(priv, l3_ipv6_addr,
1803 &rr->entries.l3_ipv6[i]);
1805 case sizeof(struct qdio_brinfo_entry_l3_ipv4):
1806 (*cb)(priv, l3_ipv4_addr,
1807 &rr->entries.l3_ipv4[i]);
1809 case sizeof(struct qdio_brinfo_entry_l2):
1810 (*cb)(priv, l2_addr_lnid,
1811 &rr->entries.l2[i]);
1818 } while (rr->response.code == 0x0107 || /* channel busy */
1819 (rr->response.code == 1 && /* list stored */
1820 /* resume token is non-zero => list incomplete */
1821 (rr->naihdr.resume_token.t1 || rr->naihdr.resume_token.t2)));
1822 (*response) = rr->response.code;
1825 free_page((unsigned long)rr);
1828 EXPORT_SYMBOL_GPL(qdio_pnso_brinfo);
1830 static int __init init_QDIO(void)
1834 rc = qdio_debug_init();
1837 rc = qdio_setup_init();
1840 rc = tiqdio_allocate_memory();
1843 rc = tiqdio_register_thinints();
1849 tiqdio_free_memory();
1857 static void __exit exit_QDIO(void)
1859 tiqdio_unregister_thinints();
1860 tiqdio_free_memory();
1865 module_init(init_QDIO);
1866 module_exit(exit_QDIO);