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_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 count,
314 unsigned int *busy_bit, unsigned long aob)
316 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
317 unsigned int fc = QDIO_SIGA_WRITE;
321 if (queue_type(q) == QDIO_IQDIO_QFMT && !multicast_outbound(q)) {
323 fc = QDIO_SIGA_WRITEM;
325 fc = QDIO_SIGA_WRITEQ;
329 schid = q->irq_ptr->sch_token;
330 fc |= QDIO_SIGA_QEBSM_FLAG;
333 cc = do_siga_output(schid, q->mask, busy_bit, fc, aob);
335 /* hipersocket busy condition */
336 if (unlikely(*busy_bit)) {
340 start_time = get_tod_clock_fast();
343 if (get_tod_clock_fast() - start_time < QDIO_BUSY_BIT_PATIENCE)
347 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr,
348 "%4x cc2 BB1:%1d", SCH_NO(q), q->nr);
349 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "count:%u", retries);
354 static inline int qdio_siga_input(struct qdio_q *q)
356 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
357 unsigned int fc = QDIO_SIGA_READ;
360 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-r:%1d", q->nr);
361 qperf_inc(q, siga_read);
364 schid = q->irq_ptr->sch_token;
365 fc |= QDIO_SIGA_QEBSM_FLAG;
368 cc = do_siga_input(schid, q->mask, fc);
370 DBF_ERROR("%4x SIGA-R:%2d", SCH_NO(q), cc);
371 return (cc) ? -EIO : 0;
374 #define qdio_siga_sync_out(q) qdio_siga_sync(q, ~0U, 0)
375 #define qdio_siga_sync_all(q) qdio_siga_sync(q, ~0U, ~0U)
377 static inline void qdio_sync_queues(struct qdio_q *q)
379 /* PCI capable outbound queues will also be scanned so sync them too */
380 if (pci_out_supported(q->irq_ptr))
381 qdio_siga_sync_all(q);
386 int debug_get_buf_state(struct qdio_q *q, unsigned int bufnr,
387 unsigned char *state)
389 if (need_siga_sync(q))
391 return get_buf_state(q, bufnr, state, 0);
394 static inline void qdio_stop_polling(struct qdio_q *q)
396 if (!q->u.in.ack_count)
399 qperf_inc(q, stop_polling);
401 /* show the card that we are not polling anymore */
402 set_buf_states(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT,
404 q->u.in.ack_count = 0;
407 static inline void account_sbals(struct qdio_q *q, unsigned int count)
411 q->q_stats.nr_sbal_total += count;
412 if (count == QDIO_MAX_BUFFERS_MASK) {
413 q->q_stats.nr_sbals[7]++;
417 q->q_stats.nr_sbals[pos]++;
420 static void process_buffer_error(struct qdio_q *q, unsigned int start,
423 q->qdio_error = QDIO_ERROR_SLSB_STATE;
425 /* special handling for no target buffer empty */
426 if (queue_type(q) == QDIO_IQDIO_QFMT && !q->is_input_q &&
427 q->sbal[start]->element[15].sflags == 0x10) {
428 qperf_inc(q, target_full);
429 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "OUTFULL FTC:%02x", start);
433 DBF_ERROR("%4x BUF ERROR", SCH_NO(q));
434 DBF_ERROR((q->is_input_q) ? "IN:%2d" : "OUT:%2d", q->nr);
435 DBF_ERROR("FTC:%3d C:%3d", start, count);
436 DBF_ERROR("F14:%2x F15:%2x",
437 q->sbal[start]->element[14].sflags,
438 q->sbal[start]->element[15].sflags);
441 static inline void inbound_primed(struct qdio_q *q, unsigned int start,
446 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in prim:%1d %02x", q->nr, count);
448 /* for QEBSM the ACK was already set by EQBS */
450 if (!q->u.in.ack_count) {
451 q->u.in.ack_count = count;
452 q->u.in.ack_start = start;
456 /* delete the previous ACK's */
457 set_buf_states(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT,
459 q->u.in.ack_count = count;
460 q->u.in.ack_start = start;
465 * ACK the newest buffer. The ACK will be removed in qdio_stop_polling
466 * or by the next inbound run.
468 new = add_buf(start, count - 1);
469 if (q->u.in.ack_count) {
470 /* reset the previous ACK but first set the new one */
471 set_buf_state(q, new, SLSB_P_INPUT_ACK);
472 set_buf_state(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT);
474 q->u.in.ack_count = 1;
475 set_buf_state(q, new, SLSB_P_INPUT_ACK);
478 q->u.in.ack_start = new;
482 /* need to change ALL buffers to get more interrupts */
483 set_buf_states(q, start, SLSB_P_INPUT_NOT_INIT, count);
486 static int get_inbound_buffer_frontier(struct qdio_q *q, unsigned int start)
488 unsigned char state = 0;
491 q->timestamp = get_tod_clock_fast();
494 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
497 count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
502 * No siga sync here, as a PCI or we after a thin interrupt
503 * already sync'ed the queues.
505 count = get_buf_states(q, start, &state, count, 1, 0);
510 case SLSB_P_INPUT_PRIMED:
511 inbound_primed(q, start, count);
512 if (atomic_sub_return(count, &q->nr_buf_used) == 0)
513 qperf_inc(q, inbound_queue_full);
514 if (q->irq_ptr->perf_stat_enabled)
515 account_sbals(q, count);
517 case SLSB_P_INPUT_ERROR:
518 process_buffer_error(q, start, count);
520 * Interrupts may be avoided as long as the error is present
521 * so change the buffer state immediately to avoid starvation.
523 set_buf_states(q, start, SLSB_P_INPUT_NOT_INIT, count);
524 if (atomic_sub_return(count, &q->nr_buf_used) == 0)
525 qperf_inc(q, inbound_queue_full);
526 if (q->irq_ptr->perf_stat_enabled)
527 account_sbals_error(q, count);
529 case SLSB_CU_INPUT_EMPTY:
530 case SLSB_P_INPUT_NOT_INIT:
531 case SLSB_P_INPUT_ACK:
532 if (q->irq_ptr->perf_stat_enabled)
533 q->q_stats.nr_sbal_nop++;
534 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in nop:%1d %#02x",
543 static int qdio_inbound_q_moved(struct qdio_q *q, unsigned int start)
547 count = get_inbound_buffer_frontier(q, start);
549 if (count && !is_thinint_irq(q->irq_ptr) && MACHINE_IS_LPAR)
550 q->u.in.timestamp = get_tod_clock();
555 static inline int qdio_inbound_q_done(struct qdio_q *q, unsigned int start)
557 unsigned char state = 0;
559 if (!atomic_read(&q->nr_buf_used))
562 if (need_siga_sync(q))
564 get_buf_state(q, start, &state, 0);
566 if (state == SLSB_P_INPUT_PRIMED || state == SLSB_P_INPUT_ERROR)
567 /* more work coming */
570 if (is_thinint_irq(q->irq_ptr))
573 /* don't poll under z/VM */
578 * At this point we know, that inbound first_to_check
579 * has (probably) not moved (see qdio_inbound_processing).
581 if (get_tod_clock_fast() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) {
582 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in done:%02x", start);
588 static inline void qdio_handle_aobs(struct qdio_q *q, int start, int count)
590 unsigned char state = 0;
593 for (j = 0; j < count; ++j) {
594 get_buf_state(q, b, &state, 0);
595 if (state == SLSB_P_OUTPUT_PENDING) {
596 struct qaob *aob = q->u.out.aobs[b];
600 q->u.out.sbal_state[b].flags |=
601 QDIO_OUTBUF_STATE_FLAG_PENDING;
602 q->u.out.aobs[b] = NULL;
608 static inline unsigned long qdio_aob_for_buffer(struct qdio_output_q *q,
611 unsigned long phys_aob = 0;
613 if (!q->aobs[bufnr]) {
614 struct qaob *aob = qdio_allocate_aob();
615 q->aobs[bufnr] = aob;
617 if (q->aobs[bufnr]) {
618 q->aobs[bufnr]->user1 = (u64) q->sbal_state[bufnr].user;
619 phys_aob = virt_to_phys(q->aobs[bufnr]);
620 WARN_ON_ONCE(phys_aob & 0xFF);
623 q->sbal_state[bufnr].flags = 0;
627 static void qdio_kick_handler(struct qdio_q *q, unsigned int count)
629 int start = q->first_to_kick;
631 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
635 qperf_inc(q, inbound_handler);
636 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "kih s:%02x c:%02x", start, count);
638 qperf_inc(q, outbound_handler);
639 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "koh: s:%02x c:%02x",
643 q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr, start, count,
644 q->irq_ptr->int_parm);
646 /* for the next time */
647 q->first_to_kick = add_buf(start, count);
651 static inline int qdio_tasklet_schedule(struct qdio_q *q)
653 if (likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE)) {
654 tasklet_schedule(&q->tasklet);
660 static void __qdio_inbound_processing(struct qdio_q *q)
662 unsigned int start = q->first_to_check;
665 qperf_inc(q, tasklet_inbound);
667 count = qdio_inbound_q_moved(q, start);
671 start = add_buf(start, count);
672 q->first_to_check = start;
673 qdio_kick_handler(q, count);
675 if (!qdio_inbound_q_done(q, start)) {
676 /* means poll time is not yet over */
677 qperf_inc(q, tasklet_inbound_resched);
678 if (!qdio_tasklet_schedule(q))
682 qdio_stop_polling(q);
684 * We need to check again to not lose initiative after
685 * resetting the ACK state.
687 if (!qdio_inbound_q_done(q, start)) {
688 qperf_inc(q, tasklet_inbound_resched2);
689 qdio_tasklet_schedule(q);
693 void qdio_inbound_processing(unsigned long data)
695 struct qdio_q *q = (struct qdio_q *)data;
696 __qdio_inbound_processing(q);
699 static int get_outbound_buffer_frontier(struct qdio_q *q, unsigned int start)
701 unsigned char state = 0;
704 q->timestamp = get_tod_clock_fast();
706 if (need_siga_sync(q))
707 if (((queue_type(q) != QDIO_IQDIO_QFMT) &&
708 !pci_out_supported(q->irq_ptr)) ||
709 (queue_type(q) == QDIO_IQDIO_QFMT &&
710 multicast_outbound(q)))
713 count = atomic_read(&q->nr_buf_used);
717 count = get_buf_states(q, start, &state, count, 0, q->u.out.use_cq);
722 case SLSB_P_OUTPUT_EMPTY:
723 case SLSB_P_OUTPUT_PENDING:
724 /* the adapter got it */
725 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr,
726 "out empty:%1d %02x", q->nr, count);
728 atomic_sub(count, &q->nr_buf_used);
729 if (q->irq_ptr->perf_stat_enabled)
730 account_sbals(q, count);
732 case SLSB_P_OUTPUT_ERROR:
733 process_buffer_error(q, start, count);
734 atomic_sub(count, &q->nr_buf_used);
735 if (q->irq_ptr->perf_stat_enabled)
736 account_sbals_error(q, count);
738 case SLSB_CU_OUTPUT_PRIMED:
739 /* the adapter has not fetched the output yet */
740 if (q->irq_ptr->perf_stat_enabled)
741 q->q_stats.nr_sbal_nop++;
742 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out primed:%1d",
745 case SLSB_P_OUTPUT_NOT_INIT:
746 case SLSB_P_OUTPUT_HALTED:
754 /* all buffers processed? */
755 static inline int qdio_outbound_q_done(struct qdio_q *q)
757 return atomic_read(&q->nr_buf_used) == 0;
760 static inline int qdio_outbound_q_moved(struct qdio_q *q, unsigned int start)
764 count = get_outbound_buffer_frontier(q, start);
767 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out moved:%1d", q->nr);
769 qdio_handle_aobs(q, start, count);
775 static int qdio_kick_outbound_q(struct qdio_q *q, unsigned int count,
779 unsigned int busy_bit;
781 if (!need_siga_out(q))
784 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w:%1d", q->nr);
786 qperf_inc(q, siga_write);
788 cc = qdio_siga_output(q, count, &busy_bit, aob);
794 while (++retries < QDIO_BUSY_BIT_RETRIES) {
795 mdelay(QDIO_BUSY_BIT_RETRY_DELAY);
798 DBF_ERROR("%4x cc2 BBC:%1d", SCH_NO(q), q->nr);
801 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w cc2:%1d", q->nr);
807 DBF_ERROR("%4x SIGA-W:%1d", SCH_NO(q), cc);
812 DBF_ERROR("%4x cc2 BB2:%1d", SCH_NO(q), q->nr);
813 DBF_ERROR("count:%u", retries);
818 static void __qdio_outbound_processing(struct qdio_q *q)
820 unsigned int start = q->first_to_check;
823 qperf_inc(q, tasklet_outbound);
824 WARN_ON_ONCE(atomic_read(&q->nr_buf_used) < 0);
826 count = qdio_outbound_q_moved(q, start);
828 q->first_to_check = add_buf(start, count);
829 qdio_kick_handler(q, count);
832 if (queue_type(q) == QDIO_ZFCP_QFMT && !pci_out_supported(q->irq_ptr) &&
833 !qdio_outbound_q_done(q))
836 if (q->u.out.pci_out_enabled)
840 * Now we know that queue type is either qeth without pci enabled
841 * or HiperSockets. Make sure buffer switch from PRIMED to EMPTY
842 * is noticed and outbound_handler is called after some time.
844 if (qdio_outbound_q_done(q))
845 del_timer_sync(&q->u.out.timer);
847 if (!timer_pending(&q->u.out.timer) &&
848 likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE))
849 mod_timer(&q->u.out.timer, jiffies + 10 * HZ);
853 qdio_tasklet_schedule(q);
856 /* outbound tasklet */
857 void qdio_outbound_processing(unsigned long data)
859 struct qdio_q *q = (struct qdio_q *)data;
860 __qdio_outbound_processing(q);
863 void qdio_outbound_timer(struct timer_list *t)
865 struct qdio_q *q = from_timer(q, t, u.out.timer);
867 qdio_tasklet_schedule(q);
870 static inline void qdio_check_outbound_pci_queues(struct qdio_irq *irq)
875 if (!pci_out_supported(irq) || !irq->scan_threshold)
878 for_each_output_queue(irq, out, i)
879 if (!qdio_outbound_q_done(out))
880 qdio_tasklet_schedule(out);
883 static void __tiqdio_inbound_processing(struct qdio_q *q)
885 unsigned int start = q->first_to_check;
888 qperf_inc(q, tasklet_inbound);
889 if (need_siga_sync(q) && need_siga_sync_after_ai(q))
892 /* The interrupt could be caused by a PCI request: */
893 qdio_check_outbound_pci_queues(q->irq_ptr);
895 count = qdio_inbound_q_moved(q, start);
899 start = add_buf(start, count);
900 q->first_to_check = start;
901 qdio_kick_handler(q, count);
903 if (!qdio_inbound_q_done(q, start)) {
904 qperf_inc(q, tasklet_inbound_resched);
905 if (!qdio_tasklet_schedule(q))
909 qdio_stop_polling(q);
911 * We need to check again to not lose initiative after
912 * resetting the ACK state.
914 if (!qdio_inbound_q_done(q, start)) {
915 qperf_inc(q, tasklet_inbound_resched2);
916 qdio_tasklet_schedule(q);
920 void tiqdio_inbound_processing(unsigned long data)
922 struct qdio_q *q = (struct qdio_q *)data;
923 __tiqdio_inbound_processing(q);
926 static inline void qdio_set_state(struct qdio_irq *irq_ptr,
927 enum qdio_irq_states state)
929 DBF_DEV_EVENT(DBF_INFO, irq_ptr, "newstate: %1d", state);
931 irq_ptr->state = state;
935 static void qdio_irq_check_sense(struct qdio_irq *irq_ptr, struct irb *irb)
937 if (irb->esw.esw0.erw.cons) {
938 DBF_ERROR("%4x sense:", irq_ptr->schid.sch_no);
939 DBF_ERROR_HEX(irb, 64);
940 DBF_ERROR_HEX(irb->ecw, 64);
944 /* PCI interrupt handler */
945 static void qdio_int_handler_pci(struct qdio_irq *irq_ptr)
950 if (unlikely(irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
953 for_each_input_queue(irq_ptr, q, i) {
954 if (q->u.in.queue_start_poll) {
955 /* skip if polling is enabled or already in work */
956 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
957 &q->u.in.queue_irq_state)) {
958 QDIO_PERF_STAT_INC(irq_ptr, int_discarded);
961 q->u.in.queue_start_poll(q->irq_ptr->cdev, q->nr,
962 q->irq_ptr->int_parm);
964 tasklet_schedule(&q->tasklet);
968 if (!pci_out_supported(irq_ptr) || !irq_ptr->scan_threshold)
971 for_each_output_queue(irq_ptr, q, i) {
972 if (qdio_outbound_q_done(q))
974 if (need_siga_sync(q) && need_siga_sync_out_after_pci(q))
976 qdio_tasklet_schedule(q);
980 static void qdio_handle_activate_check(struct ccw_device *cdev,
981 unsigned long intparm, int cstat, int dstat)
983 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
987 DBF_ERROR("%4x ACT CHECK", irq_ptr->schid.sch_no);
988 DBF_ERROR("intp :%lx", intparm);
989 DBF_ERROR("ds: %2x cs:%2x", dstat, cstat);
991 if (irq_ptr->nr_input_qs) {
992 q = irq_ptr->input_qs[0];
993 } else if (irq_ptr->nr_output_qs) {
994 q = irq_ptr->output_qs[0];
1000 count = sub_buf(q->first_to_check, q->first_to_kick);
1001 q->handler(q->irq_ptr->cdev, QDIO_ERROR_ACTIVATE,
1002 q->nr, q->first_to_kick, count, irq_ptr->int_parm);
1004 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
1006 * In case of z/VM LGR (Live Guest Migration) QDIO recovery will happen.
1007 * Therefore we call the LGR detection function here.
1012 static void qdio_establish_handle_irq(struct ccw_device *cdev, int cstat,
1015 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1017 DBF_DEV_EVENT(DBF_INFO, irq_ptr, "qest irq");
1021 if (dstat & ~(DEV_STAT_DEV_END | DEV_STAT_CHN_END))
1023 if (!(dstat & DEV_STAT_DEV_END))
1025 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ESTABLISHED);
1029 DBF_ERROR("%4x EQ:error", irq_ptr->schid.sch_no);
1030 DBF_ERROR("ds: %2x cs:%2x", dstat, cstat);
1031 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
1034 /* qdio interrupt handler */
1035 void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
1038 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1039 struct subchannel_id schid;
1042 if (!intparm || !irq_ptr) {
1043 ccw_device_get_schid(cdev, &schid);
1044 DBF_ERROR("qint:%4x", schid.sch_no);
1048 if (irq_ptr->perf_stat_enabled)
1049 irq_ptr->perf_stat.qdio_int++;
1052 DBF_ERROR("%4x IO error", irq_ptr->schid.sch_no);
1053 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
1054 wake_up(&cdev->private->wait_q);
1057 qdio_irq_check_sense(irq_ptr, irb);
1058 cstat = irb->scsw.cmd.cstat;
1059 dstat = irb->scsw.cmd.dstat;
1061 switch (irq_ptr->state) {
1062 case QDIO_IRQ_STATE_INACTIVE:
1063 qdio_establish_handle_irq(cdev, cstat, dstat);
1065 case QDIO_IRQ_STATE_CLEANUP:
1066 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1068 case QDIO_IRQ_STATE_ESTABLISHED:
1069 case QDIO_IRQ_STATE_ACTIVE:
1070 if (cstat & SCHN_STAT_PCI) {
1071 qdio_int_handler_pci(irq_ptr);
1075 qdio_handle_activate_check(cdev, intparm, cstat,
1078 case QDIO_IRQ_STATE_STOPPED:
1083 wake_up(&cdev->private->wait_q);
1087 * qdio_get_ssqd_desc - get qdio subchannel description
1088 * @cdev: ccw device to get description for
1089 * @data: where to store the ssqd
1091 * Returns 0 or an error code. The results of the chsc are stored in the
1092 * specified structure.
1094 int qdio_get_ssqd_desc(struct ccw_device *cdev,
1095 struct qdio_ssqd_desc *data)
1097 struct subchannel_id schid;
1099 if (!cdev || !cdev->private)
1102 ccw_device_get_schid(cdev, &schid);
1103 DBF_EVENT("get ssqd:%4x", schid.sch_no);
1104 return qdio_setup_get_ssqd(NULL, &schid, data);
1106 EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc);
1108 static void qdio_shutdown_queues(struct ccw_device *cdev)
1110 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1114 for_each_input_queue(irq_ptr, q, i)
1115 tasklet_kill(&q->tasklet);
1117 for_each_output_queue(irq_ptr, q, i) {
1118 del_timer_sync(&q->u.out.timer);
1119 tasklet_kill(&q->tasklet);
1124 * qdio_shutdown - shut down a qdio subchannel
1125 * @cdev: associated ccw device
1126 * @how: use halt or clear to shutdown
1128 int qdio_shutdown(struct ccw_device *cdev, int how)
1130 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1131 struct subchannel_id schid;
1137 WARN_ON_ONCE(irqs_disabled());
1138 ccw_device_get_schid(cdev, &schid);
1139 DBF_EVENT("qshutdown:%4x", schid.sch_no);
1141 mutex_lock(&irq_ptr->setup_mutex);
1143 * Subchannel was already shot down. We cannot prevent being called
1144 * twice since cio may trigger a shutdown asynchronously.
1146 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1147 mutex_unlock(&irq_ptr->setup_mutex);
1152 * Indicate that the device is going down. Scheduling the queue
1153 * tasklets is forbidden from here on.
1155 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
1157 tiqdio_remove_device(irq_ptr);
1158 qdio_shutdown_queues(cdev);
1159 qdio_shutdown_debug_entries(irq_ptr);
1161 /* cleanup subchannel */
1162 spin_lock_irq(get_ccwdev_lock(cdev));
1164 if (how & QDIO_FLAG_CLEANUP_USING_CLEAR)
1165 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
1167 /* default behaviour is halt */
1168 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
1170 DBF_ERROR("%4x SHUTD ERR", irq_ptr->schid.sch_no);
1171 DBF_ERROR("rc:%4d", rc);
1175 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
1176 spin_unlock_irq(get_ccwdev_lock(cdev));
1177 wait_event_interruptible_timeout(cdev->private->wait_q,
1178 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
1179 irq_ptr->state == QDIO_IRQ_STATE_ERR,
1181 spin_lock_irq(get_ccwdev_lock(cdev));
1184 qdio_shutdown_thinint(irq_ptr);
1186 /* restore interrupt handler */
1187 if ((void *)cdev->handler == (void *)qdio_int_handler) {
1188 cdev->handler = irq_ptr->orig_handler;
1189 cdev->private->intparm = 0;
1191 spin_unlock_irq(get_ccwdev_lock(cdev));
1193 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1194 mutex_unlock(&irq_ptr->setup_mutex);
1199 EXPORT_SYMBOL_GPL(qdio_shutdown);
1202 * qdio_free - free data structures for a qdio subchannel
1203 * @cdev: associated ccw device
1205 int qdio_free(struct ccw_device *cdev)
1207 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1208 struct subchannel_id schid;
1213 ccw_device_get_schid(cdev, &schid);
1214 DBF_EVENT("qfree:%4x", schid.sch_no);
1215 DBF_DEV_EVENT(DBF_ERR, irq_ptr, "dbf abandoned");
1216 mutex_lock(&irq_ptr->setup_mutex);
1218 irq_ptr->debug_area = NULL;
1219 cdev->private->qdio_data = NULL;
1220 mutex_unlock(&irq_ptr->setup_mutex);
1222 qdio_release_memory(irq_ptr);
1225 EXPORT_SYMBOL_GPL(qdio_free);
1228 * qdio_allocate - allocate qdio queues and associated data
1229 * @init_data: initialization data
1231 int qdio_allocate(struct qdio_initialize *init_data)
1233 struct subchannel_id schid;
1234 struct qdio_irq *irq_ptr;
1236 ccw_device_get_schid(init_data->cdev, &schid);
1237 DBF_EVENT("qallocate:%4x", schid.sch_no);
1239 if ((init_data->no_input_qs && !init_data->input_handler) ||
1240 (init_data->no_output_qs && !init_data->output_handler))
1243 if ((init_data->no_input_qs > QDIO_MAX_QUEUES_PER_IRQ) ||
1244 (init_data->no_output_qs > QDIO_MAX_QUEUES_PER_IRQ))
1247 if ((!init_data->input_sbal_addr_array) ||
1248 (!init_data->output_sbal_addr_array))
1251 /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */
1252 irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1256 mutex_init(&irq_ptr->setup_mutex);
1257 if (qdio_allocate_dbf(init_data, irq_ptr))
1261 * Allocate a page for the chsc calls in qdio_establish.
1262 * Must be pre-allocated since a zfcp recovery will call
1263 * qdio_establish. In case of low memory and swap on a zfcp disk
1264 * we may not be able to allocate memory otherwise.
1266 irq_ptr->chsc_page = get_zeroed_page(GFP_KERNEL);
1267 if (!irq_ptr->chsc_page)
1270 /* qdr is used in ccw1.cda which is u32 */
1271 irq_ptr->qdr = (struct qdr *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1275 if (qdio_allocate_qs(irq_ptr, init_data->no_input_qs,
1276 init_data->no_output_qs))
1279 INIT_LIST_HEAD(&irq_ptr->entry);
1280 init_data->cdev->private->qdio_data = irq_ptr;
1281 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1284 qdio_release_memory(irq_ptr);
1288 EXPORT_SYMBOL_GPL(qdio_allocate);
1290 static void qdio_detect_hsicq(struct qdio_irq *irq_ptr)
1292 struct qdio_q *q = irq_ptr->input_qs[0];
1295 if (irq_ptr->nr_input_qs > 1 && queue_type(q) == QDIO_IQDIO_QFMT)
1298 for_each_output_queue(irq_ptr, q, i) {
1300 if (multicast_outbound(q))
1302 if (qdio_enable_async_operation(&q->u.out) < 0) {
1307 qdio_disable_async_operation(&q->u.out);
1309 DBF_EVENT("use_cq:%d", use_cq);
1313 * qdio_establish - establish queues on a qdio subchannel
1314 * @init_data: initialization data
1316 int qdio_establish(struct qdio_initialize *init_data)
1318 struct ccw_device *cdev = init_data->cdev;
1319 struct subchannel_id schid;
1320 struct qdio_irq *irq_ptr;
1323 ccw_device_get_schid(cdev, &schid);
1324 DBF_EVENT("qestablish:%4x", schid.sch_no);
1326 irq_ptr = cdev->private->qdio_data;
1330 mutex_lock(&irq_ptr->setup_mutex);
1331 qdio_setup_irq(init_data);
1333 rc = qdio_establish_thinint(irq_ptr);
1335 mutex_unlock(&irq_ptr->setup_mutex);
1336 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1341 irq_ptr->ccw.cmd_code = irq_ptr->equeue.cmd;
1342 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1343 irq_ptr->ccw.count = irq_ptr->equeue.count;
1344 irq_ptr->ccw.cda = (u32)((addr_t)irq_ptr->qdr);
1346 spin_lock_irq(get_ccwdev_lock(cdev));
1347 ccw_device_set_options_mask(cdev, 0);
1349 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ESTABLISH, 0, 0);
1350 spin_unlock_irq(get_ccwdev_lock(cdev));
1352 DBF_ERROR("%4x est IO ERR", irq_ptr->schid.sch_no);
1353 DBF_ERROR("rc:%4x", rc);
1354 mutex_unlock(&irq_ptr->setup_mutex);
1355 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1359 wait_event_interruptible_timeout(cdev->private->wait_q,
1360 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
1361 irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ);
1363 if (irq_ptr->state != QDIO_IRQ_STATE_ESTABLISHED) {
1364 mutex_unlock(&irq_ptr->setup_mutex);
1365 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1369 qdio_setup_ssqd_info(irq_ptr);
1371 qdio_detect_hsicq(irq_ptr);
1373 /* qebsm is now setup if available, initialize buffer states */
1374 qdio_init_buf_states(irq_ptr);
1376 mutex_unlock(&irq_ptr->setup_mutex);
1377 qdio_print_subchannel_info(irq_ptr, cdev);
1378 qdio_setup_debug_entries(irq_ptr, cdev);
1381 EXPORT_SYMBOL_GPL(qdio_establish);
1384 * qdio_activate - activate queues on a qdio subchannel
1385 * @cdev: associated cdev
1387 int qdio_activate(struct ccw_device *cdev)
1389 struct subchannel_id schid;
1390 struct qdio_irq *irq_ptr;
1393 ccw_device_get_schid(cdev, &schid);
1394 DBF_EVENT("qactivate:%4x", schid.sch_no);
1396 irq_ptr = cdev->private->qdio_data;
1400 mutex_lock(&irq_ptr->setup_mutex);
1401 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1406 irq_ptr->ccw.cmd_code = irq_ptr->aqueue.cmd;
1407 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1408 irq_ptr->ccw.count = irq_ptr->aqueue.count;
1409 irq_ptr->ccw.cda = 0;
1411 spin_lock_irq(get_ccwdev_lock(cdev));
1412 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
1414 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ACTIVATE,
1415 0, DOIO_DENY_PREFETCH);
1416 spin_unlock_irq(get_ccwdev_lock(cdev));
1418 DBF_ERROR("%4x act IO ERR", irq_ptr->schid.sch_no);
1419 DBF_ERROR("rc:%4x", rc);
1423 if (is_thinint_irq(irq_ptr))
1424 tiqdio_add_device(irq_ptr);
1426 /* wait for subchannel to become active */
1429 switch (irq_ptr->state) {
1430 case QDIO_IRQ_STATE_STOPPED:
1431 case QDIO_IRQ_STATE_ERR:
1435 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
1439 mutex_unlock(&irq_ptr->setup_mutex);
1442 EXPORT_SYMBOL_GPL(qdio_activate);
1444 static inline int buf_in_between(int bufnr, int start, int count)
1446 int end = add_buf(start, count);
1449 if (bufnr >= start && bufnr < end)
1455 /* wrap-around case */
1456 if ((bufnr >= start && bufnr <= QDIO_MAX_BUFFERS_PER_Q) ||
1464 * handle_inbound - reset processed input buffers
1465 * @q: queue containing the buffers
1467 * @bufnr: first buffer to process
1468 * @count: how many buffers are emptied
1470 static int handle_inbound(struct qdio_q *q, unsigned int callflags,
1471 int bufnr, int count)
1475 qperf_inc(q, inbound_call);
1477 if (!q->u.in.ack_count)
1480 /* protect against stop polling setting an ACK for an emptied slsb */
1481 if (count == QDIO_MAX_BUFFERS_PER_Q) {
1482 /* overwriting everything, just delete polling status */
1483 q->u.in.ack_count = 0;
1485 } else if (buf_in_between(q->u.in.ack_start, bufnr, count)) {
1487 /* partial overwrite, just update ack_start */
1488 diff = add_buf(bufnr, count);
1489 diff = sub_buf(diff, q->u.in.ack_start);
1490 q->u.in.ack_count -= diff;
1491 if (q->u.in.ack_count <= 0) {
1492 q->u.in.ack_count = 0;
1495 q->u.in.ack_start = add_buf(q->u.in.ack_start, diff);
1497 /* the only ACK will be deleted */
1498 q->u.in.ack_count = 0;
1503 count = set_buf_states(q, bufnr, SLSB_CU_INPUT_EMPTY, count);
1504 atomic_add(count, &q->nr_buf_used);
1506 if (need_siga_in(q))
1507 return qdio_siga_input(q);
1513 * handle_outbound - process filled outbound buffers
1514 * @q: queue containing the buffers
1516 * @bufnr: first buffer to process
1517 * @count: how many buffers are filled
1519 static int handle_outbound(struct qdio_q *q, unsigned int callflags,
1520 unsigned int bufnr, unsigned int count)
1522 const unsigned int scan_threshold = q->irq_ptr->scan_threshold;
1523 unsigned char state = 0;
1526 qperf_inc(q, outbound_call);
1528 count = set_buf_states(q, bufnr, SLSB_CU_OUTPUT_PRIMED, count);
1529 used = atomic_add_return(count, &q->nr_buf_used);
1531 if (used == QDIO_MAX_BUFFERS_PER_Q)
1532 qperf_inc(q, outbound_queue_full);
1534 if (callflags & QDIO_FLAG_PCI_OUT) {
1535 q->u.out.pci_out_enabled = 1;
1536 qperf_inc(q, pci_request_int);
1538 q->u.out.pci_out_enabled = 0;
1540 if (queue_type(q) == QDIO_IQDIO_QFMT) {
1541 unsigned long phys_aob = 0;
1543 if (q->u.out.use_cq && count == 1)
1544 phys_aob = qdio_aob_for_buffer(&q->u.out, bufnr);
1546 rc = qdio_kick_outbound_q(q, count, phys_aob);
1547 } else if (need_siga_sync(q)) {
1548 rc = qdio_siga_sync_q(q);
1549 } else if (count < QDIO_MAX_BUFFERS_PER_Q &&
1550 get_buf_state(q, prev_buf(bufnr), &state, 0) > 0 &&
1551 state == SLSB_CU_OUTPUT_PRIMED) {
1552 /* The previous buffer is not processed yet, tack on. */
1553 qperf_inc(q, fast_requeue);
1555 rc = qdio_kick_outbound_q(q, count, 0);
1558 /* Let drivers implement their own completion scanning: */
1559 if (!scan_threshold)
1562 /* in case of SIGA errors we must process the error immediately */
1563 if (used >= scan_threshold || rc)
1564 qdio_tasklet_schedule(q);
1566 /* free the SBALs in case of no further traffic */
1567 if (!timer_pending(&q->u.out.timer) &&
1568 likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE))
1569 mod_timer(&q->u.out.timer, jiffies + HZ);
1574 * do_QDIO - process input or output buffers
1575 * @cdev: associated ccw_device for the qdio subchannel
1576 * @callflags: input or output and special flags from the program
1577 * @q_nr: queue number
1578 * @bufnr: buffer number
1579 * @count: how many buffers to process
1581 int do_QDIO(struct ccw_device *cdev, unsigned int callflags,
1582 int q_nr, unsigned int bufnr, unsigned int count)
1584 struct qdio_irq *irq_ptr;
1586 if (bufnr >= QDIO_MAX_BUFFERS_PER_Q || count > QDIO_MAX_BUFFERS_PER_Q)
1589 irq_ptr = cdev->private->qdio_data;
1593 DBF_DEV_EVENT(DBF_INFO, irq_ptr,
1594 "do%02x b:%02x c:%02x", callflags, bufnr, count);
1596 if (irq_ptr->state != QDIO_IRQ_STATE_ACTIVE)
1600 if (callflags & QDIO_FLAG_SYNC_INPUT)
1601 return handle_inbound(irq_ptr->input_qs[q_nr],
1602 callflags, bufnr, count);
1603 else if (callflags & QDIO_FLAG_SYNC_OUTPUT)
1604 return handle_outbound(irq_ptr->output_qs[q_nr],
1605 callflags, bufnr, count);
1608 EXPORT_SYMBOL_GPL(do_QDIO);
1611 * qdio_start_irq - process input buffers
1612 * @cdev: associated ccw_device for the qdio subchannel
1613 * @nr: input queue number
1617 * 1 - irqs not started since new data is available
1619 int qdio_start_irq(struct ccw_device *cdev, int nr)
1622 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1626 q = irq_ptr->input_qs[nr];
1628 clear_nonshared_ind(irq_ptr);
1629 qdio_stop_polling(q);
1630 clear_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state);
1633 * We need to check again to not lose initiative after
1634 * resetting the ACK state.
1636 if (test_nonshared_ind(irq_ptr))
1638 if (!qdio_inbound_q_done(q, q->first_to_check))
1643 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
1644 &q->u.in.queue_irq_state))
1650 EXPORT_SYMBOL(qdio_start_irq);
1652 static int __qdio_inspect_queue(struct qdio_q *q, unsigned int *bufnr,
1653 unsigned int *error)
1655 unsigned int start = q->first_to_check;
1658 count = q->is_input_q ? qdio_inbound_q_moved(q, start) :
1659 qdio_outbound_q_moved(q, start);
1664 *error = q->qdio_error;
1666 /* for the next time */
1667 q->first_to_check = add_buf(start, count);
1673 int qdio_inspect_queue(struct ccw_device *cdev, unsigned int nr, bool is_input,
1674 unsigned int *bufnr, unsigned int *error)
1676 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1681 q = is_input ? irq_ptr->input_qs[nr] : irq_ptr->output_qs[nr];
1683 if (need_siga_sync(q))
1684 qdio_siga_sync_q(q);
1686 return __qdio_inspect_queue(q, bufnr, error);
1688 EXPORT_SYMBOL_GPL(qdio_inspect_queue);
1691 * qdio_get_next_buffers - process input buffers
1692 * @cdev: associated ccw_device for the qdio subchannel
1693 * @nr: input queue number
1694 * @bufnr: first filled buffer number
1695 * @error: buffers are in error state
1699 * = 0 - no new buffers found
1700 * > 0 - number of processed buffers
1702 int qdio_get_next_buffers(struct ccw_device *cdev, int nr, int *bufnr,
1706 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1710 q = irq_ptr->input_qs[nr];
1713 * Cannot rely on automatic sync after interrupt since queues may
1714 * also be examined without interrupt.
1716 if (need_siga_sync(q))
1717 qdio_sync_queues(q);
1719 qdio_check_outbound_pci_queues(irq_ptr);
1721 /* Note: upper-layer MUST stop processing immediately here ... */
1722 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
1725 return __qdio_inspect_queue(q, bufnr, error);
1727 EXPORT_SYMBOL(qdio_get_next_buffers);
1730 * qdio_stop_irq - disable interrupt processing for the device
1731 * @cdev: associated ccw_device for the qdio subchannel
1732 * @nr: input queue number
1735 * 0 - interrupts were already disabled
1736 * 1 - interrupts successfully disabled
1738 int qdio_stop_irq(struct ccw_device *cdev, int nr)
1741 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1745 q = irq_ptr->input_qs[nr];
1747 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
1748 &q->u.in.queue_irq_state))
1753 EXPORT_SYMBOL(qdio_stop_irq);
1756 * qdio_pnso_brinfo() - perform network subchannel op #0 - bridge info.
1757 * @schid: Subchannel ID.
1758 * @cnc: Boolean Change-Notification Control
1759 * @response: Response code will be stored at this address
1760 * @cb: Callback function will be executed for each element
1761 * of the address list
1762 * @priv: Pointer to pass to the callback function.
1764 * Performs "Store-network-bridging-information list" operation and calls
1765 * the callback function for every entry in the list. If "change-
1766 * notification-control" is set, further changes in the address list
1767 * will be reported via the IPA command.
1769 int qdio_pnso_brinfo(struct subchannel_id schid,
1770 int cnc, u16 *response,
1771 void (*cb)(void *priv, enum qdio_brinfo_entry_type type,
1775 struct chsc_pnso_area *rr;
1777 u32 prev_instance = 0;
1778 int isfirstblock = 1;
1781 rr = (struct chsc_pnso_area *)get_zeroed_page(GFP_KERNEL);
1785 /* on the first iteration, naihdr.resume_token will be zero */
1786 rc = chsc_pnso_brinfo(schid, rr, rr->naihdr.resume_token, cnc);
1787 if (rc != 0 && rc != -EBUSY)
1789 if (rr->response.code != 1) {
1798 size = rr->naihdr.naids;
1799 elems = (rr->response.length -
1800 sizeof(struct chsc_header) -
1801 sizeof(struct chsc_brinfo_naihdr)) /
1804 if (!isfirstblock && (rr->naihdr.instance != prev_instance)) {
1805 /* Inform the caller that they need to scrap */
1806 /* the data that was already reported via cb */
1811 prev_instance = rr->naihdr.instance;
1812 for (i = 0; i < elems; i++)
1814 case sizeof(struct qdio_brinfo_entry_l3_ipv6):
1815 (*cb)(priv, l3_ipv6_addr,
1816 &rr->entries.l3_ipv6[i]);
1818 case sizeof(struct qdio_brinfo_entry_l3_ipv4):
1819 (*cb)(priv, l3_ipv4_addr,
1820 &rr->entries.l3_ipv4[i]);
1822 case sizeof(struct qdio_brinfo_entry_l2):
1823 (*cb)(priv, l2_addr_lnid,
1824 &rr->entries.l2[i]);
1831 } while (rr->response.code == 0x0107 || /* channel busy */
1832 (rr->response.code == 1 && /* list stored */
1833 /* resume token is non-zero => list incomplete */
1834 (rr->naihdr.resume_token.t1 || rr->naihdr.resume_token.t2)));
1835 (*response) = rr->response.code;
1838 free_page((unsigned long)rr);
1841 EXPORT_SYMBOL_GPL(qdio_pnso_brinfo);
1843 static int __init init_QDIO(void)
1847 rc = qdio_debug_init();
1850 rc = qdio_setup_init();
1853 rc = tiqdio_allocate_memory();
1856 rc = tiqdio_register_thinints();
1862 tiqdio_free_memory();
1870 static void __exit exit_QDIO(void)
1872 tiqdio_unregister_thinints();
1873 tiqdio_free_memory();
1878 module_init(init_QDIO);
1879 module_exit(exit_QDIO);