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;
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",
152 return count - tmp_count;
155 DBF_ERROR("%4x EQBS ERROR", SCH_NO(q));
156 DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
157 q->handler(q->irq_ptr->cdev, QDIO_ERROR_GET_BUF_STATE,
158 q->nr, q->first_to_kick, count, q->irq_ptr->int_parm);
163 * qdio_do_sqbs - set buffer states for QEBSM
164 * @q: queue to manipulate
165 * @state: new state of the buffers
166 * @start: first buffer number to change
167 * @count: how many buffers to change
169 * Returns the number of successfully changed buffers.
170 * Does retrying until the specified count of buffer states is set or an
173 static int qdio_do_sqbs(struct qdio_q *q, unsigned char state, int start,
176 unsigned int ccq = 0;
177 int tmp_count = count, tmp_start = start;
186 nr += q->irq_ptr->nr_input_qs;
188 ccq = do_sqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count);
189 rc = qdio_check_ccq(q, ccq);
191 WARN_ON_ONCE(tmp_count);
192 return count - tmp_count;
195 if (rc == 1 || rc == 2) {
196 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "SQBS again:%2d", ccq);
197 qperf_inc(q, sqbs_partial);
201 DBF_ERROR("%4x SQBS ERROR", SCH_NO(q));
202 DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
203 q->handler(q->irq_ptr->cdev, QDIO_ERROR_SET_BUF_STATE,
204 q->nr, q->first_to_kick, count, q->irq_ptr->int_parm);
209 * Returns number of examined buffers and their common state in *state.
210 * Requested number of buffers-to-examine must be > 0.
212 static inline int get_buf_states(struct qdio_q *q, unsigned int bufnr,
213 unsigned char *state, unsigned int count,
214 int auto_ack, int merge_pending)
216 unsigned char __state = 0;
220 return qdio_do_eqbs(q, state, bufnr, count, auto_ack);
222 /* get initial state: */
223 __state = q->slsb.val[bufnr];
224 if (merge_pending && __state == SLSB_P_OUTPUT_PENDING)
225 __state = SLSB_P_OUTPUT_EMPTY;
227 for (i = 1; i < count; i++) {
228 bufnr = next_buf(bufnr);
230 /* merge PENDING into EMPTY: */
232 q->slsb.val[bufnr] == SLSB_P_OUTPUT_PENDING &&
233 __state == SLSB_P_OUTPUT_EMPTY)
236 /* stop if next state differs from initial state: */
237 if (q->slsb.val[bufnr] != __state)
244 static inline int get_buf_state(struct qdio_q *q, unsigned int bufnr,
245 unsigned char *state, int auto_ack)
247 return get_buf_states(q, bufnr, state, 1, auto_ack, 0);
250 /* wrap-around safe setting of slsb states, returns number of changed buffers */
251 static inline int set_buf_states(struct qdio_q *q, int bufnr,
252 unsigned char state, int count)
257 return qdio_do_sqbs(q, state, bufnr, count);
259 for (i = 0; i < count; i++) {
260 xchg(&q->slsb.val[bufnr], state);
261 bufnr = next_buf(bufnr);
266 static inline int set_buf_state(struct qdio_q *q, int bufnr,
269 return set_buf_states(q, bufnr, state, 1);
272 /* set slsb states to initial state */
273 static void qdio_init_buf_states(struct qdio_irq *irq_ptr)
278 for_each_input_queue(irq_ptr, q, i)
279 set_buf_states(q, 0, SLSB_P_INPUT_NOT_INIT,
280 QDIO_MAX_BUFFERS_PER_Q);
281 for_each_output_queue(irq_ptr, q, i)
282 set_buf_states(q, 0, SLSB_P_OUTPUT_NOT_INIT,
283 QDIO_MAX_BUFFERS_PER_Q);
286 static inline int qdio_siga_sync(struct qdio_q *q, unsigned int output,
289 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
290 unsigned int fc = QDIO_SIGA_SYNC;
293 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-s:%1d", q->nr);
294 qperf_inc(q, siga_sync);
297 schid = q->irq_ptr->sch_token;
298 fc |= QDIO_SIGA_QEBSM_FLAG;
301 cc = do_siga_sync(schid, output, input, fc);
303 DBF_ERROR("%4x SIGA-S:%2d", SCH_NO(q), cc);
304 return (cc) ? -EIO : 0;
307 static inline int qdio_siga_sync_q(struct qdio_q *q)
310 return qdio_siga_sync(q, 0, q->mask);
312 return qdio_siga_sync(q, q->mask, 0);
315 static int qdio_siga_output(struct qdio_q *q, unsigned int *busy_bit,
318 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
319 unsigned int fc = QDIO_SIGA_WRITE;
322 unsigned long laob = 0;
324 WARN_ON_ONCE(aob && ((queue_type(q) != QDIO_IQDIO_QFMT) ||
326 if (q->u.out.use_cq && aob != 0) {
327 fc = QDIO_SIGA_WRITEQ;
332 schid = q->irq_ptr->sch_token;
333 fc |= QDIO_SIGA_QEBSM_FLAG;
336 cc = do_siga_output(schid, q->mask, busy_bit, fc, laob);
338 /* hipersocket busy condition */
339 if (unlikely(*busy_bit)) {
343 start_time = get_tod_clock_fast();
346 if (get_tod_clock_fast() - start_time < QDIO_BUSY_BIT_PATIENCE)
350 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr,
351 "%4x cc2 BB1:%1d", SCH_NO(q), q->nr);
352 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "count:%u", retries);
357 static inline int qdio_siga_input(struct qdio_q *q)
359 unsigned long schid = *((u32 *) &q->irq_ptr->schid);
360 unsigned int fc = QDIO_SIGA_READ;
363 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-r:%1d", q->nr);
364 qperf_inc(q, siga_read);
367 schid = q->irq_ptr->sch_token;
368 fc |= QDIO_SIGA_QEBSM_FLAG;
371 cc = do_siga_input(schid, q->mask, fc);
373 DBF_ERROR("%4x SIGA-R:%2d", SCH_NO(q), cc);
374 return (cc) ? -EIO : 0;
377 #define qdio_siga_sync_out(q) qdio_siga_sync(q, ~0U, 0)
378 #define qdio_siga_sync_all(q) qdio_siga_sync(q, ~0U, ~0U)
380 static inline void qdio_sync_queues(struct qdio_q *q)
382 /* PCI capable outbound queues will also be scanned so sync them too */
383 if (pci_out_supported(q))
384 qdio_siga_sync_all(q);
389 int debug_get_buf_state(struct qdio_q *q, unsigned int bufnr,
390 unsigned char *state)
392 if (need_siga_sync(q))
394 return get_buf_states(q, bufnr, state, 1, 0, 0);
397 static inline void qdio_stop_polling(struct qdio_q *q)
399 if (!q->u.in.polling)
403 qperf_inc(q, stop_polling);
405 /* show the card that we are not polling anymore */
407 set_buf_states(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT,
409 q->u.in.ack_count = 0;
411 set_buf_state(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT);
414 static inline void account_sbals(struct qdio_q *q, unsigned int count)
418 q->q_stats.nr_sbal_total += count;
419 if (count == QDIO_MAX_BUFFERS_MASK) {
420 q->q_stats.nr_sbals[7]++;
424 q->q_stats.nr_sbals[pos]++;
427 static void process_buffer_error(struct qdio_q *q, int count)
429 unsigned char state = (q->is_input_q) ? SLSB_P_INPUT_NOT_INIT :
430 SLSB_P_OUTPUT_NOT_INIT;
432 q->qdio_error = QDIO_ERROR_SLSB_STATE;
434 /* special handling for no target buffer empty */
435 if ((!q->is_input_q &&
436 (q->sbal[q->first_to_check]->element[15].sflags) == 0x10)) {
437 qperf_inc(q, target_full);
438 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "OUTFULL FTC:%02x",
443 DBF_ERROR("%4x BUF ERROR", SCH_NO(q));
444 DBF_ERROR((q->is_input_q) ? "IN:%2d" : "OUT:%2d", q->nr);
445 DBF_ERROR("FTC:%3d C:%3d", q->first_to_check, count);
446 DBF_ERROR("F14:%2x F15:%2x",
447 q->sbal[q->first_to_check]->element[14].sflags,
448 q->sbal[q->first_to_check]->element[15].sflags);
452 * Interrupts may be avoided as long as the error is present
453 * so change the buffer state immediately to avoid starvation.
455 set_buf_states(q, q->first_to_check, state, count);
458 static inline void inbound_primed(struct qdio_q *q, int count)
462 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in prim:%1d %02x", q->nr, count);
464 /* for QEBSM the ACK was already set by EQBS */
466 if (!q->u.in.polling) {
468 q->u.in.ack_count = count;
469 q->u.in.ack_start = q->first_to_check;
473 /* delete the previous ACK's */
474 set_buf_states(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT,
476 q->u.in.ack_count = count;
477 q->u.in.ack_start = q->first_to_check;
482 * ACK the newest buffer. The ACK will be removed in qdio_stop_polling
483 * or by the next inbound run.
485 new = add_buf(q->first_to_check, count - 1);
486 if (q->u.in.polling) {
487 /* reset the previous ACK but first set the new one */
488 set_buf_state(q, new, SLSB_P_INPUT_ACK);
489 set_buf_state(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT);
492 set_buf_state(q, new, SLSB_P_INPUT_ACK);
495 q->u.in.ack_start = new;
499 /* need to change ALL buffers to get more interrupts */
500 set_buf_states(q, q->first_to_check, SLSB_P_INPUT_NOT_INIT, count);
503 static int get_inbound_buffer_frontier(struct qdio_q *q)
506 unsigned char state = 0;
508 q->timestamp = get_tod_clock_fast();
511 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
514 count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
515 stop = add_buf(q->first_to_check, count);
517 if (q->first_to_check == stop)
521 * No siga sync here, as a PCI or we after a thin interrupt
522 * already sync'ed the queues.
524 count = get_buf_states(q, q->first_to_check, &state, count, 1, 0);
529 case SLSB_P_INPUT_PRIMED:
530 inbound_primed(q, count);
531 q->first_to_check = add_buf(q->first_to_check, count);
532 if (atomic_sub_return(count, &q->nr_buf_used) == 0)
533 qperf_inc(q, inbound_queue_full);
534 if (q->irq_ptr->perf_stat_enabled)
535 account_sbals(q, count);
537 case SLSB_P_INPUT_ERROR:
538 process_buffer_error(q, count);
539 q->first_to_check = add_buf(q->first_to_check, count);
540 atomic_sub(count, &q->nr_buf_used);
541 if (q->irq_ptr->perf_stat_enabled)
542 account_sbals_error(q, count);
544 case SLSB_CU_INPUT_EMPTY:
545 case SLSB_P_INPUT_NOT_INIT:
546 case SLSB_P_INPUT_ACK:
547 if (q->irq_ptr->perf_stat_enabled)
548 q->q_stats.nr_sbal_nop++;
549 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in nop:%1d %#02x",
550 q->nr, q->first_to_check);
556 return q->first_to_check;
559 static int qdio_inbound_q_moved(struct qdio_q *q)
563 bufnr = get_inbound_buffer_frontier(q);
565 if (bufnr != q->last_move) {
566 q->last_move = bufnr;
567 if (!is_thinint_irq(q->irq_ptr) && MACHINE_IS_LPAR)
568 q->u.in.timestamp = get_tod_clock();
574 static inline int qdio_inbound_q_done(struct qdio_q *q)
576 unsigned char state = 0;
578 if (!atomic_read(&q->nr_buf_used))
581 if (need_siga_sync(q))
583 get_buf_state(q, q->first_to_check, &state, 0);
585 if (state == SLSB_P_INPUT_PRIMED || state == SLSB_P_INPUT_ERROR)
586 /* more work coming */
589 if (is_thinint_irq(q->irq_ptr))
592 /* don't poll under z/VM */
597 * At this point we know, that inbound first_to_check
598 * has (probably) not moved (see qdio_inbound_processing).
600 if (get_tod_clock_fast() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) {
601 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in done:%02x",
608 static inline int contains_aobs(struct qdio_q *q)
610 return !q->is_input_q && q->u.out.use_cq;
613 static inline void qdio_handle_aobs(struct qdio_q *q, int start, int count)
615 unsigned char state = 0;
618 if (!contains_aobs(q))
621 for (j = 0; j < count; ++j) {
622 get_buf_state(q, b, &state, 0);
623 if (state == SLSB_P_OUTPUT_PENDING) {
624 struct qaob *aob = q->u.out.aobs[b];
628 q->u.out.sbal_state[b].flags |=
629 QDIO_OUTBUF_STATE_FLAG_PENDING;
630 q->u.out.aobs[b] = NULL;
631 } else if (state == SLSB_P_OUTPUT_EMPTY) {
632 q->u.out.sbal_state[b].aob = NULL;
638 static inline unsigned long qdio_aob_for_buffer(struct qdio_output_q *q,
641 unsigned long phys_aob = 0;
646 if (!q->aobs[bufnr]) {
647 struct qaob *aob = qdio_allocate_aob();
648 q->aobs[bufnr] = aob;
650 if (q->aobs[bufnr]) {
651 q->sbal_state[bufnr].aob = q->aobs[bufnr];
652 q->aobs[bufnr]->user1 = (u64) q->sbal_state[bufnr].user;
653 phys_aob = virt_to_phys(q->aobs[bufnr]);
654 WARN_ON_ONCE(phys_aob & 0xFF);
657 q->sbal_state[bufnr].flags = 0;
661 static void qdio_kick_handler(struct qdio_q *q)
663 int start = q->first_to_kick;
664 int end = q->first_to_check;
667 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
670 count = sub_buf(end, start);
673 qperf_inc(q, inbound_handler);
674 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "kih s:%02x c:%02x", start, count);
676 qperf_inc(q, outbound_handler);
677 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "koh: s:%02x c:%02x",
681 qdio_handle_aobs(q, start, count);
683 q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr, start, count,
684 q->irq_ptr->int_parm);
686 /* for the next time */
687 q->first_to_kick = end;
691 static inline int qdio_tasklet_schedule(struct qdio_q *q)
693 if (likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE)) {
694 tasklet_schedule(&q->tasklet);
700 static void __qdio_inbound_processing(struct qdio_q *q)
702 qperf_inc(q, tasklet_inbound);
704 if (!qdio_inbound_q_moved(q))
707 qdio_kick_handler(q);
709 if (!qdio_inbound_q_done(q)) {
710 /* means poll time is not yet over */
711 qperf_inc(q, tasklet_inbound_resched);
712 if (!qdio_tasklet_schedule(q))
716 qdio_stop_polling(q);
718 * We need to check again to not lose initiative after
719 * resetting the ACK state.
721 if (!qdio_inbound_q_done(q)) {
722 qperf_inc(q, tasklet_inbound_resched2);
723 qdio_tasklet_schedule(q);
727 void qdio_inbound_processing(unsigned long data)
729 struct qdio_q *q = (struct qdio_q *)data;
730 __qdio_inbound_processing(q);
733 static int get_outbound_buffer_frontier(struct qdio_q *q)
736 unsigned char state = 0;
738 q->timestamp = get_tod_clock_fast();
740 if (need_siga_sync(q))
741 if (((queue_type(q) != QDIO_IQDIO_QFMT) &&
742 !pci_out_supported(q)) ||
743 (queue_type(q) == QDIO_IQDIO_QFMT &&
744 multicast_outbound(q)))
748 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
751 count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
752 stop = add_buf(q->first_to_check, count);
753 if (q->first_to_check == stop)
756 count = get_buf_states(q, q->first_to_check, &state, count, 0, 1);
761 case SLSB_P_OUTPUT_EMPTY:
762 case SLSB_P_OUTPUT_PENDING:
763 /* the adapter got it */
764 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr,
765 "out empty:%1d %02x", q->nr, count);
767 atomic_sub(count, &q->nr_buf_used);
768 q->first_to_check = add_buf(q->first_to_check, count);
769 if (q->irq_ptr->perf_stat_enabled)
770 account_sbals(q, count);
773 case SLSB_P_OUTPUT_ERROR:
774 process_buffer_error(q, count);
775 q->first_to_check = add_buf(q->first_to_check, count);
776 atomic_sub(count, &q->nr_buf_used);
777 if (q->irq_ptr->perf_stat_enabled)
778 account_sbals_error(q, count);
780 case SLSB_CU_OUTPUT_PRIMED:
781 /* the adapter has not fetched the output yet */
782 if (q->irq_ptr->perf_stat_enabled)
783 q->q_stats.nr_sbal_nop++;
784 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out primed:%1d",
787 case SLSB_P_OUTPUT_NOT_INIT:
788 case SLSB_P_OUTPUT_HALTED:
795 return q->first_to_check;
798 /* all buffers processed? */
799 static inline int qdio_outbound_q_done(struct qdio_q *q)
801 return atomic_read(&q->nr_buf_used) == 0;
804 static inline int qdio_outbound_q_moved(struct qdio_q *q)
808 bufnr = get_outbound_buffer_frontier(q);
810 if (bufnr != q->last_move) {
811 q->last_move = bufnr;
812 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out moved:%1d", q->nr);
818 static int qdio_kick_outbound_q(struct qdio_q *q, unsigned long aob)
821 unsigned int busy_bit;
823 if (!need_siga_out(q))
826 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w:%1d", q->nr);
828 qperf_inc(q, siga_write);
830 cc = qdio_siga_output(q, &busy_bit, aob);
836 while (++retries < QDIO_BUSY_BIT_RETRIES) {
837 mdelay(QDIO_BUSY_BIT_RETRY_DELAY);
840 DBF_ERROR("%4x cc2 BBC:%1d", SCH_NO(q), q->nr);
843 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w cc2:%1d", q->nr);
849 DBF_ERROR("%4x SIGA-W:%1d", SCH_NO(q), cc);
854 DBF_ERROR("%4x cc2 BB2:%1d", SCH_NO(q), q->nr);
855 DBF_ERROR("count:%u", retries);
860 static void __qdio_outbound_processing(struct qdio_q *q)
862 qperf_inc(q, tasklet_outbound);
863 WARN_ON_ONCE(atomic_read(&q->nr_buf_used) < 0);
865 if (qdio_outbound_q_moved(q))
866 qdio_kick_handler(q);
868 if (queue_type(q) == QDIO_ZFCP_QFMT)
869 if (!pci_out_supported(q) && !qdio_outbound_q_done(q))
872 if (q->u.out.pci_out_enabled)
876 * Now we know that queue type is either qeth without pci enabled
877 * or HiperSockets. Make sure buffer switch from PRIMED to EMPTY
878 * is noticed and outbound_handler is called after some time.
880 if (qdio_outbound_q_done(q))
881 del_timer_sync(&q->u.out.timer);
883 if (!timer_pending(&q->u.out.timer) &&
884 likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE))
885 mod_timer(&q->u.out.timer, jiffies + 10 * HZ);
889 qdio_tasklet_schedule(q);
892 /* outbound tasklet */
893 void qdio_outbound_processing(unsigned long data)
895 struct qdio_q *q = (struct qdio_q *)data;
896 __qdio_outbound_processing(q);
899 void qdio_outbound_timer(unsigned long data)
901 struct qdio_q *q = (struct qdio_q *)data;
903 qdio_tasklet_schedule(q);
906 static inline void qdio_check_outbound_after_thinint(struct qdio_q *q)
911 if (!pci_out_supported(q))
914 for_each_output_queue(q->irq_ptr, out, i)
915 if (!qdio_outbound_q_done(out))
916 qdio_tasklet_schedule(out);
919 static void __tiqdio_inbound_processing(struct qdio_q *q)
921 qperf_inc(q, tasklet_inbound);
922 if (need_siga_sync(q) && need_siga_sync_after_ai(q))
926 * The interrupt could be caused by a PCI request. Check the
927 * PCI capable outbound queues.
929 qdio_check_outbound_after_thinint(q);
931 if (!qdio_inbound_q_moved(q))
934 qdio_kick_handler(q);
936 if (!qdio_inbound_q_done(q)) {
937 qperf_inc(q, tasklet_inbound_resched);
938 if (!qdio_tasklet_schedule(q))
942 qdio_stop_polling(q);
944 * We need to check again to not lose initiative after
945 * resetting the ACK state.
947 if (!qdio_inbound_q_done(q)) {
948 qperf_inc(q, tasklet_inbound_resched2);
949 qdio_tasklet_schedule(q);
953 void tiqdio_inbound_processing(unsigned long data)
955 struct qdio_q *q = (struct qdio_q *)data;
956 __tiqdio_inbound_processing(q);
959 static inline void qdio_set_state(struct qdio_irq *irq_ptr,
960 enum qdio_irq_states state)
962 DBF_DEV_EVENT(DBF_INFO, irq_ptr, "newstate: %1d", state);
964 irq_ptr->state = state;
968 static void qdio_irq_check_sense(struct qdio_irq *irq_ptr, struct irb *irb)
970 if (irb->esw.esw0.erw.cons) {
971 DBF_ERROR("%4x sense:", irq_ptr->schid.sch_no);
972 DBF_ERROR_HEX(irb, 64);
973 DBF_ERROR_HEX(irb->ecw, 64);
977 /* PCI interrupt handler */
978 static void qdio_int_handler_pci(struct qdio_irq *irq_ptr)
983 if (unlikely(irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
986 for_each_input_queue(irq_ptr, q, i) {
987 if (q->u.in.queue_start_poll) {
988 /* skip if polling is enabled or already in work */
989 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
990 &q->u.in.queue_irq_state)) {
991 qperf_inc(q, int_discarded);
994 q->u.in.queue_start_poll(q->irq_ptr->cdev, q->nr,
995 q->irq_ptr->int_parm);
997 tasklet_schedule(&q->tasklet);
1001 if (!(irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED))
1004 for_each_output_queue(irq_ptr, q, i) {
1005 if (qdio_outbound_q_done(q))
1007 if (need_siga_sync(q) && need_siga_sync_out_after_pci(q))
1008 qdio_siga_sync_q(q);
1009 qdio_tasklet_schedule(q);
1013 static void qdio_handle_activate_check(struct ccw_device *cdev,
1014 unsigned long intparm, int cstat, int dstat)
1016 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1020 DBF_ERROR("%4x ACT CHECK", irq_ptr->schid.sch_no);
1021 DBF_ERROR("intp :%lx", intparm);
1022 DBF_ERROR("ds: %2x cs:%2x", dstat, cstat);
1024 if (irq_ptr->nr_input_qs) {
1025 q = irq_ptr->input_qs[0];
1026 } else if (irq_ptr->nr_output_qs) {
1027 q = irq_ptr->output_qs[0];
1033 count = sub_buf(q->first_to_check, q->first_to_kick);
1034 q->handler(q->irq_ptr->cdev, QDIO_ERROR_ACTIVATE,
1035 q->nr, q->first_to_kick, count, irq_ptr->int_parm);
1037 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
1039 * In case of z/VM LGR (Live Guest Migration) QDIO recovery will happen.
1040 * Therefore we call the LGR detection function here.
1045 static void qdio_establish_handle_irq(struct ccw_device *cdev, int cstat,
1048 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1050 DBF_DEV_EVENT(DBF_INFO, irq_ptr, "qest irq");
1054 if (dstat & ~(DEV_STAT_DEV_END | DEV_STAT_CHN_END))
1056 if (!(dstat & DEV_STAT_DEV_END))
1058 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ESTABLISHED);
1062 DBF_ERROR("%4x EQ:error", irq_ptr->schid.sch_no);
1063 DBF_ERROR("ds: %2x cs:%2x", dstat, cstat);
1064 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
1067 /* qdio interrupt handler */
1068 void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
1071 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1072 struct subchannel_id schid;
1075 if (!intparm || !irq_ptr) {
1076 ccw_device_get_schid(cdev, &schid);
1077 DBF_ERROR("qint:%4x", schid.sch_no);
1081 if (irq_ptr->perf_stat_enabled)
1082 irq_ptr->perf_stat.qdio_int++;
1085 DBF_ERROR("%4x IO error", irq_ptr->schid.sch_no);
1086 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
1087 wake_up(&cdev->private->wait_q);
1090 qdio_irq_check_sense(irq_ptr, irb);
1091 cstat = irb->scsw.cmd.cstat;
1092 dstat = irb->scsw.cmd.dstat;
1094 switch (irq_ptr->state) {
1095 case QDIO_IRQ_STATE_INACTIVE:
1096 qdio_establish_handle_irq(cdev, cstat, dstat);
1098 case QDIO_IRQ_STATE_CLEANUP:
1099 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1101 case QDIO_IRQ_STATE_ESTABLISHED:
1102 case QDIO_IRQ_STATE_ACTIVE:
1103 if (cstat & SCHN_STAT_PCI) {
1104 qdio_int_handler_pci(irq_ptr);
1108 qdio_handle_activate_check(cdev, intparm, cstat,
1111 case QDIO_IRQ_STATE_STOPPED:
1116 wake_up(&cdev->private->wait_q);
1120 * qdio_get_ssqd_desc - get qdio subchannel description
1121 * @cdev: ccw device to get description for
1122 * @data: where to store the ssqd
1124 * Returns 0 or an error code. The results of the chsc are stored in the
1125 * specified structure.
1127 int qdio_get_ssqd_desc(struct ccw_device *cdev,
1128 struct qdio_ssqd_desc *data)
1130 struct subchannel_id schid;
1132 if (!cdev || !cdev->private)
1135 ccw_device_get_schid(cdev, &schid);
1136 DBF_EVENT("get ssqd:%4x", schid.sch_no);
1137 return qdio_setup_get_ssqd(NULL, &schid, data);
1139 EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc);
1141 static void qdio_shutdown_queues(struct ccw_device *cdev)
1143 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1147 for_each_input_queue(irq_ptr, q, i)
1148 tasklet_kill(&q->tasklet);
1150 for_each_output_queue(irq_ptr, q, i) {
1151 del_timer_sync(&q->u.out.timer);
1152 tasklet_kill(&q->tasklet);
1157 * qdio_shutdown - shut down a qdio subchannel
1158 * @cdev: associated ccw device
1159 * @how: use halt or clear to shutdown
1161 int qdio_shutdown(struct ccw_device *cdev, int how)
1163 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1164 struct subchannel_id schid;
1170 WARN_ON_ONCE(irqs_disabled());
1171 ccw_device_get_schid(cdev, &schid);
1172 DBF_EVENT("qshutdown:%4x", schid.sch_no);
1174 mutex_lock(&irq_ptr->setup_mutex);
1176 * Subchannel was already shot down. We cannot prevent being called
1177 * twice since cio may trigger a shutdown asynchronously.
1179 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1180 mutex_unlock(&irq_ptr->setup_mutex);
1185 * Indicate that the device is going down. Scheduling the queue
1186 * tasklets is forbidden from here on.
1188 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
1190 tiqdio_remove_input_queues(irq_ptr);
1191 qdio_shutdown_queues(cdev);
1192 qdio_shutdown_debug_entries(irq_ptr);
1194 /* cleanup subchannel */
1195 spin_lock_irq(get_ccwdev_lock(cdev));
1197 if (how & QDIO_FLAG_CLEANUP_USING_CLEAR)
1198 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
1200 /* default behaviour is halt */
1201 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
1203 DBF_ERROR("%4x SHUTD ERR", irq_ptr->schid.sch_no);
1204 DBF_ERROR("rc:%4d", rc);
1208 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
1209 spin_unlock_irq(get_ccwdev_lock(cdev));
1210 wait_event_interruptible_timeout(cdev->private->wait_q,
1211 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
1212 irq_ptr->state == QDIO_IRQ_STATE_ERR,
1214 spin_lock_irq(get_ccwdev_lock(cdev));
1217 qdio_shutdown_thinint(irq_ptr);
1219 /* restore interrupt handler */
1220 if ((void *)cdev->handler == (void *)qdio_int_handler)
1221 cdev->handler = irq_ptr->orig_handler;
1222 spin_unlock_irq(get_ccwdev_lock(cdev));
1224 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1225 mutex_unlock(&irq_ptr->setup_mutex);
1230 EXPORT_SYMBOL_GPL(qdio_shutdown);
1233 * qdio_free - free data structures for a qdio subchannel
1234 * @cdev: associated ccw device
1236 int qdio_free(struct ccw_device *cdev)
1238 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1239 struct subchannel_id schid;
1244 ccw_device_get_schid(cdev, &schid);
1245 DBF_EVENT("qfree:%4x", schid.sch_no);
1246 DBF_DEV_EVENT(DBF_ERR, irq_ptr, "dbf abandoned");
1247 mutex_lock(&irq_ptr->setup_mutex);
1249 irq_ptr->debug_area = NULL;
1250 cdev->private->qdio_data = NULL;
1251 mutex_unlock(&irq_ptr->setup_mutex);
1253 qdio_release_memory(irq_ptr);
1256 EXPORT_SYMBOL_GPL(qdio_free);
1259 * qdio_allocate - allocate qdio queues and associated data
1260 * @init_data: initialization data
1262 int qdio_allocate(struct qdio_initialize *init_data)
1264 struct subchannel_id schid;
1265 struct qdio_irq *irq_ptr;
1267 ccw_device_get_schid(init_data->cdev, &schid);
1268 DBF_EVENT("qallocate:%4x", schid.sch_no);
1270 if ((init_data->no_input_qs && !init_data->input_handler) ||
1271 (init_data->no_output_qs && !init_data->output_handler))
1274 if ((init_data->no_input_qs > QDIO_MAX_QUEUES_PER_IRQ) ||
1275 (init_data->no_output_qs > QDIO_MAX_QUEUES_PER_IRQ))
1278 if ((!init_data->input_sbal_addr_array) ||
1279 (!init_data->output_sbal_addr_array))
1282 /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */
1283 irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1287 mutex_init(&irq_ptr->setup_mutex);
1288 if (qdio_allocate_dbf(init_data, irq_ptr))
1292 * Allocate a page for the chsc calls in qdio_establish.
1293 * Must be pre-allocated since a zfcp recovery will call
1294 * qdio_establish. In case of low memory and swap on a zfcp disk
1295 * we may not be able to allocate memory otherwise.
1297 irq_ptr->chsc_page = get_zeroed_page(GFP_KERNEL);
1298 if (!irq_ptr->chsc_page)
1301 /* qdr is used in ccw1.cda which is u32 */
1302 irq_ptr->qdr = (struct qdr *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1306 if (qdio_allocate_qs(irq_ptr, init_data->no_input_qs,
1307 init_data->no_output_qs))
1310 init_data->cdev->private->qdio_data = irq_ptr;
1311 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1314 qdio_release_memory(irq_ptr);
1318 EXPORT_SYMBOL_GPL(qdio_allocate);
1320 static void qdio_detect_hsicq(struct qdio_irq *irq_ptr)
1322 struct qdio_q *q = irq_ptr->input_qs[0];
1325 if (irq_ptr->nr_input_qs > 1 && queue_type(q) == QDIO_IQDIO_QFMT)
1328 for_each_output_queue(irq_ptr, q, i) {
1330 if (qdio_enable_async_operation(&q->u.out) < 0) {
1335 qdio_disable_async_operation(&q->u.out);
1337 DBF_EVENT("use_cq:%d", use_cq);
1341 * qdio_establish - establish queues on a qdio subchannel
1342 * @init_data: initialization data
1344 int qdio_establish(struct qdio_initialize *init_data)
1346 struct ccw_device *cdev = init_data->cdev;
1347 struct subchannel_id schid;
1348 struct qdio_irq *irq_ptr;
1351 ccw_device_get_schid(cdev, &schid);
1352 DBF_EVENT("qestablish:%4x", schid.sch_no);
1354 irq_ptr = cdev->private->qdio_data;
1358 mutex_lock(&irq_ptr->setup_mutex);
1359 qdio_setup_irq(init_data);
1361 rc = qdio_establish_thinint(irq_ptr);
1363 mutex_unlock(&irq_ptr->setup_mutex);
1364 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1369 irq_ptr->ccw.cmd_code = irq_ptr->equeue.cmd;
1370 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1371 irq_ptr->ccw.count = irq_ptr->equeue.count;
1372 irq_ptr->ccw.cda = (u32)((addr_t)irq_ptr->qdr);
1374 spin_lock_irq(get_ccwdev_lock(cdev));
1375 ccw_device_set_options_mask(cdev, 0);
1377 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ESTABLISH, 0, 0);
1378 spin_unlock_irq(get_ccwdev_lock(cdev));
1380 DBF_ERROR("%4x est IO ERR", irq_ptr->schid.sch_no);
1381 DBF_ERROR("rc:%4x", rc);
1382 mutex_unlock(&irq_ptr->setup_mutex);
1383 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1387 wait_event_interruptible_timeout(cdev->private->wait_q,
1388 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
1389 irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ);
1391 if (irq_ptr->state != QDIO_IRQ_STATE_ESTABLISHED) {
1392 mutex_unlock(&irq_ptr->setup_mutex);
1393 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1397 qdio_setup_ssqd_info(irq_ptr);
1399 qdio_detect_hsicq(irq_ptr);
1401 /* qebsm is now setup if available, initialize buffer states */
1402 qdio_init_buf_states(irq_ptr);
1404 mutex_unlock(&irq_ptr->setup_mutex);
1405 qdio_print_subchannel_info(irq_ptr, cdev);
1406 qdio_setup_debug_entries(irq_ptr, cdev);
1409 EXPORT_SYMBOL_GPL(qdio_establish);
1412 * qdio_activate - activate queues on a qdio subchannel
1413 * @cdev: associated cdev
1415 int qdio_activate(struct ccw_device *cdev)
1417 struct subchannel_id schid;
1418 struct qdio_irq *irq_ptr;
1421 ccw_device_get_schid(cdev, &schid);
1422 DBF_EVENT("qactivate:%4x", schid.sch_no);
1424 irq_ptr = cdev->private->qdio_data;
1428 mutex_lock(&irq_ptr->setup_mutex);
1429 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1434 irq_ptr->ccw.cmd_code = irq_ptr->aqueue.cmd;
1435 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1436 irq_ptr->ccw.count = irq_ptr->aqueue.count;
1437 irq_ptr->ccw.cda = 0;
1439 spin_lock_irq(get_ccwdev_lock(cdev));
1440 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
1442 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ACTIVATE,
1443 0, DOIO_DENY_PREFETCH);
1444 spin_unlock_irq(get_ccwdev_lock(cdev));
1446 DBF_ERROR("%4x act IO ERR", irq_ptr->schid.sch_no);
1447 DBF_ERROR("rc:%4x", rc);
1451 if (is_thinint_irq(irq_ptr))
1452 tiqdio_add_input_queues(irq_ptr);
1454 /* wait for subchannel to become active */
1457 switch (irq_ptr->state) {
1458 case QDIO_IRQ_STATE_STOPPED:
1459 case QDIO_IRQ_STATE_ERR:
1463 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
1467 mutex_unlock(&irq_ptr->setup_mutex);
1470 EXPORT_SYMBOL_GPL(qdio_activate);
1472 static inline int buf_in_between(int bufnr, int start, int count)
1474 int end = add_buf(start, count);
1477 if (bufnr >= start && bufnr < end)
1483 /* wrap-around case */
1484 if ((bufnr >= start && bufnr <= QDIO_MAX_BUFFERS_PER_Q) ||
1492 * handle_inbound - reset processed input buffers
1493 * @q: queue containing the buffers
1495 * @bufnr: first buffer to process
1496 * @count: how many buffers are emptied
1498 static int handle_inbound(struct qdio_q *q, unsigned int callflags,
1499 int bufnr, int count)
1503 qperf_inc(q, inbound_call);
1505 if (!q->u.in.polling)
1508 /* protect against stop polling setting an ACK for an emptied slsb */
1509 if (count == QDIO_MAX_BUFFERS_PER_Q) {
1510 /* overwriting everything, just delete polling status */
1511 q->u.in.polling = 0;
1512 q->u.in.ack_count = 0;
1514 } else if (buf_in_between(q->u.in.ack_start, bufnr, count)) {
1516 /* partial overwrite, just update ack_start */
1517 diff = add_buf(bufnr, count);
1518 diff = sub_buf(diff, q->u.in.ack_start);
1519 q->u.in.ack_count -= diff;
1520 if (q->u.in.ack_count <= 0) {
1521 q->u.in.polling = 0;
1522 q->u.in.ack_count = 0;
1525 q->u.in.ack_start = add_buf(q->u.in.ack_start, diff);
1528 /* the only ACK will be deleted, so stop polling */
1529 q->u.in.polling = 0;
1533 count = set_buf_states(q, bufnr, SLSB_CU_INPUT_EMPTY, count);
1534 atomic_add(count, &q->nr_buf_used);
1536 if (need_siga_in(q))
1537 return qdio_siga_input(q);
1543 * handle_outbound - process filled outbound buffers
1544 * @q: queue containing the buffers
1546 * @bufnr: first buffer to process
1547 * @count: how many buffers are filled
1549 static int handle_outbound(struct qdio_q *q, unsigned int callflags,
1550 int bufnr, int count)
1552 unsigned char state = 0;
1555 qperf_inc(q, outbound_call);
1557 count = set_buf_states(q, bufnr, SLSB_CU_OUTPUT_PRIMED, count);
1558 used = atomic_add_return(count, &q->nr_buf_used);
1560 if (used == QDIO_MAX_BUFFERS_PER_Q)
1561 qperf_inc(q, outbound_queue_full);
1563 if (callflags & QDIO_FLAG_PCI_OUT) {
1564 q->u.out.pci_out_enabled = 1;
1565 qperf_inc(q, pci_request_int);
1567 q->u.out.pci_out_enabled = 0;
1569 if (queue_type(q) == QDIO_IQDIO_QFMT) {
1570 unsigned long phys_aob = 0;
1572 /* One SIGA-W per buffer required for unicast HSI */
1573 WARN_ON_ONCE(count > 1 && !multicast_outbound(q));
1575 phys_aob = qdio_aob_for_buffer(&q->u.out, bufnr);
1577 rc = qdio_kick_outbound_q(q, phys_aob);
1578 } else if (need_siga_sync(q)) {
1579 rc = qdio_siga_sync_q(q);
1580 } else if (count < QDIO_MAX_BUFFERS_PER_Q &&
1581 get_buf_state(q, prev_buf(bufnr), &state, 0) > 0 &&
1582 state == SLSB_CU_OUTPUT_PRIMED) {
1583 /* The previous buffer is not processed yet, tack on. */
1584 qperf_inc(q, fast_requeue);
1586 rc = qdio_kick_outbound_q(q, 0);
1589 /* in case of SIGA errors we must process the error immediately */
1590 if (used >= q->u.out.scan_threshold || rc)
1591 qdio_tasklet_schedule(q);
1593 /* free the SBALs in case of no further traffic */
1594 if (!timer_pending(&q->u.out.timer) &&
1595 likely(q->irq_ptr->state == QDIO_IRQ_STATE_ACTIVE))
1596 mod_timer(&q->u.out.timer, jiffies + HZ);
1601 * do_QDIO - process input or output buffers
1602 * @cdev: associated ccw_device for the qdio subchannel
1603 * @callflags: input or output and special flags from the program
1604 * @q_nr: queue number
1605 * @bufnr: buffer number
1606 * @count: how many buffers to process
1608 int do_QDIO(struct ccw_device *cdev, unsigned int callflags,
1609 int q_nr, unsigned int bufnr, unsigned int count)
1611 struct qdio_irq *irq_ptr;
1613 if (bufnr >= QDIO_MAX_BUFFERS_PER_Q || count > QDIO_MAX_BUFFERS_PER_Q)
1616 irq_ptr = cdev->private->qdio_data;
1620 DBF_DEV_EVENT(DBF_INFO, irq_ptr,
1621 "do%02x b:%02x c:%02x", callflags, bufnr, count);
1623 if (irq_ptr->state != QDIO_IRQ_STATE_ACTIVE)
1627 if (callflags & QDIO_FLAG_SYNC_INPUT)
1628 return handle_inbound(irq_ptr->input_qs[q_nr],
1629 callflags, bufnr, count);
1630 else if (callflags & QDIO_FLAG_SYNC_OUTPUT)
1631 return handle_outbound(irq_ptr->output_qs[q_nr],
1632 callflags, bufnr, count);
1635 EXPORT_SYMBOL_GPL(do_QDIO);
1638 * qdio_start_irq - process input buffers
1639 * @cdev: associated ccw_device for the qdio subchannel
1640 * @nr: input queue number
1644 * 1 - irqs not started since new data is available
1646 int qdio_start_irq(struct ccw_device *cdev, int nr)
1649 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1653 q = irq_ptr->input_qs[nr];
1655 clear_nonshared_ind(irq_ptr);
1656 qdio_stop_polling(q);
1657 clear_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state);
1660 * We need to check again to not lose initiative after
1661 * resetting the ACK state.
1663 if (test_nonshared_ind(irq_ptr))
1665 if (!qdio_inbound_q_done(q))
1670 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
1671 &q->u.in.queue_irq_state))
1677 EXPORT_SYMBOL(qdio_start_irq);
1680 * qdio_get_next_buffers - process input buffers
1681 * @cdev: associated ccw_device for the qdio subchannel
1682 * @nr: input queue number
1683 * @bufnr: first filled buffer number
1684 * @error: buffers are in error state
1688 * = 0 - no new buffers found
1689 * > 0 - number of processed buffers
1691 int qdio_get_next_buffers(struct ccw_device *cdev, int nr, int *bufnr,
1696 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1700 q = irq_ptr->input_qs[nr];
1703 * Cannot rely on automatic sync after interrupt since queues may
1704 * also be examined without interrupt.
1706 if (need_siga_sync(q))
1707 qdio_sync_queues(q);
1709 /* check the PCI capable outbound queues. */
1710 qdio_check_outbound_after_thinint(q);
1712 if (!qdio_inbound_q_moved(q))
1715 /* Note: upper-layer MUST stop processing immediately here ... */
1716 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
1719 start = q->first_to_kick;
1720 end = q->first_to_check;
1722 *error = q->qdio_error;
1724 /* for the next time */
1725 q->first_to_kick = end;
1727 return sub_buf(end, start);
1729 EXPORT_SYMBOL(qdio_get_next_buffers);
1732 * qdio_stop_irq - disable interrupt processing for the device
1733 * @cdev: associated ccw_device for the qdio subchannel
1734 * @nr: input queue number
1737 * 0 - interrupts were already disabled
1738 * 1 - interrupts successfully disabled
1740 int qdio_stop_irq(struct ccw_device *cdev, int nr)
1743 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1747 q = irq_ptr->input_qs[nr];
1749 if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
1750 &q->u.in.queue_irq_state))
1755 EXPORT_SYMBOL(qdio_stop_irq);
1758 * qdio_pnso_brinfo() - perform network subchannel op #0 - bridge info.
1759 * @schid: Subchannel ID.
1760 * @cnc: Boolean Change-Notification Control
1761 * @response: Response code will be stored at this address
1762 * @cb: Callback function will be executed for each element
1763 * of the address list
1764 * @priv: Pointer passed from the caller to qdio_pnso_brinfo()
1765 * @type: Type of the address entry passed to the callback
1766 * @entry: Entry containg the address of the specified type
1767 * @priv: Pointer to pass to the callback function.
1769 * Performs "Store-network-bridging-information list" operation and calls
1770 * the callback function for every entry in the list. If "change-
1771 * notification-control" is set, further changes in the address list
1772 * will be reported via the IPA command.
1774 int qdio_pnso_brinfo(struct subchannel_id schid,
1775 int cnc, u16 *response,
1776 void (*cb)(void *priv, enum qdio_brinfo_entry_type type,
1780 struct chsc_pnso_area *rr;
1782 u32 prev_instance = 0;
1783 int isfirstblock = 1;
1786 rr = (struct chsc_pnso_area *)get_zeroed_page(GFP_KERNEL);
1790 /* on the first iteration, naihdr.resume_token will be zero */
1791 rc = chsc_pnso_brinfo(schid, rr, rr->naihdr.resume_token, cnc);
1792 if (rc != 0 && rc != -EBUSY)
1794 if (rr->response.code != 1) {
1803 size = rr->naihdr.naids;
1804 elems = (rr->response.length -
1805 sizeof(struct chsc_header) -
1806 sizeof(struct chsc_brinfo_naihdr)) /
1809 if (!isfirstblock && (rr->naihdr.instance != prev_instance)) {
1810 /* Inform the caller that they need to scrap */
1811 /* the data that was already reported via cb */
1816 prev_instance = rr->naihdr.instance;
1817 for (i = 0; i < elems; i++)
1819 case sizeof(struct qdio_brinfo_entry_l3_ipv6):
1820 (*cb)(priv, l3_ipv6_addr,
1821 &rr->entries.l3_ipv6[i]);
1823 case sizeof(struct qdio_brinfo_entry_l3_ipv4):
1824 (*cb)(priv, l3_ipv4_addr,
1825 &rr->entries.l3_ipv4[i]);
1827 case sizeof(struct qdio_brinfo_entry_l2):
1828 (*cb)(priv, l2_addr_lnid,
1829 &rr->entries.l2[i]);
1836 } while (rr->response.code == 0x0107 || /* channel busy */
1837 (rr->response.code == 1 && /* list stored */
1838 /* resume token is non-zero => list incomplete */
1839 (rr->naihdr.resume_token.t1 || rr->naihdr.resume_token.t2)));
1840 (*response) = rr->response.code;
1843 free_page((unsigned long)rr);
1846 EXPORT_SYMBOL_GPL(qdio_pnso_brinfo);
1848 static int __init init_QDIO(void)
1852 rc = qdio_debug_init();
1855 rc = qdio_setup_init();
1858 rc = tiqdio_allocate_memory();
1861 rc = tiqdio_register_thinints();
1867 tiqdio_free_memory();
1875 static void __exit exit_QDIO(void)
1877 tiqdio_unregister_thinints();
1878 tiqdio_free_memory();
1883 module_init(init_QDIO);
1884 module_exit(exit_QDIO);