2 * linux/drivers/s390/cio/qdio_main.c
4 * Linux for s390 qdio support, buffer handling, qdio API and module support.
6 * Copyright 2000,2008 IBM Corp.
7 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
8 * Jan Glauber <jang@linux.vnet.ibm.com>
9 * 2.6 cio integration by Cornelia Huck <cornelia.huck@de.ibm.com>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/timer.h>
15 #include <linux/delay.h>
16 #include <asm/atomic.h>
17 #include <asm/debug.h>
24 #include "qdio_debug.h"
25 #include "qdio_perf.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(struct subchannel_id schid,
33 unsigned int out_mask, unsigned int in_mask)
35 register unsigned long __fc asm ("0") = 2;
36 register struct subchannel_id __schid asm ("1") = schid;
37 register unsigned long out asm ("2") = out_mask;
38 register unsigned long in asm ("3") = in_mask;
46 : "d" (__fc), "d" (__schid), "d" (out), "d" (in) : "cc");
50 static inline int do_siga_input(struct subchannel_id schid, unsigned int mask)
52 register unsigned long __fc asm ("0") = 1;
53 register struct subchannel_id __schid asm ("1") = schid;
54 register unsigned long __mask asm ("2") = mask;
62 : "d" (__fc), "d" (__schid), "d" (__mask) : "cc", "memory");
67 * do_siga_output - perform SIGA-w/wt function
68 * @schid: subchannel id or in case of QEBSM the subchannel token
69 * @mask: which output queues to process
70 * @bb: busy bit indicator, set only if SIGA-w/wt could not access a buffer
71 * @fc: function code to perform
73 * Returns cc or QDIO_ERROR_SIGA_ACCESS_EXCEPTION.
74 * Note: For IQDC unicast queues only the highest priority queue is processed.
76 static inline int do_siga_output(unsigned long schid, unsigned long mask,
77 u32 *bb, unsigned int fc)
79 register unsigned long __fc asm("0") = fc;
80 register unsigned long __schid asm("1") = schid;
81 register unsigned long __mask asm("2") = mask;
82 int cc = QDIO_ERROR_SIGA_ACCESS_EXCEPTION;
90 : "+d" (cc), "+d" (__fc), "+d" (__schid), "+d" (__mask)
92 *bb = ((unsigned int) __fc) >> 31;
96 static inline int qdio_check_ccq(struct qdio_q *q, unsigned int ccq)
100 /* all done or next buffer state different */
101 if (ccq == 0 || ccq == 32)
103 /* not all buffers processed */
104 if (ccq == 96 || ccq == 97)
106 /* notify devices immediately */
107 sprintf(dbf_text, "%d", ccq);
108 QDIO_DBF_TEXT2(1, trace, dbf_text);
113 * qdio_do_eqbs - extract buffer states for QEBSM
114 * @q: queue to manipulate
115 * @state: state of the extracted buffers
116 * @start: buffer number to start at
117 * @count: count of buffers to examine
119 * Returns the number of successfull extracted equal buffer states.
120 * Stops processing if a state is different from the last buffers state.
122 static int qdio_do_eqbs(struct qdio_q *q, unsigned char *state,
123 int start, int count)
125 unsigned int ccq = 0;
126 int tmp_count = count, tmp_start = start;
131 BUG_ON(!q->irq_ptr->sch_token);
134 nr += q->irq_ptr->nr_input_qs;
136 ccq = do_eqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count);
137 rc = qdio_check_ccq(q, ccq);
139 /* At least one buffer was processed, return and extract the remaining
142 if ((ccq == 96) && (count != tmp_count))
143 return (count - tmp_count);
145 QDIO_DBF_TEXT5(1, trace, "eqAGAIN");
150 QDIO_DBF_TEXT2(1, trace, "eqberr");
151 sprintf(dbf_text, "%2x,%2x,%d,%d", count, tmp_count, ccq, nr);
152 QDIO_DBF_TEXT2(1, trace, dbf_text);
153 q->handler(q->irq_ptr->cdev,
154 QDIO_ERROR_ACTIVATE_CHECK_CONDITION,
155 0, -1, -1, q->irq_ptr->int_parm);
158 return count - tmp_count;
162 * qdio_do_sqbs - set buffer states for QEBSM
163 * @q: queue to manipulate
164 * @state: new state of the buffers
165 * @start: first buffer number to change
166 * @count: how many buffers to change
168 * Returns the number of successfully changed buffers.
169 * Does retrying until the specified count of buffer states is set or an
172 static int qdio_do_sqbs(struct qdio_q *q, unsigned char state, int start,
175 unsigned int ccq = 0;
176 int tmp_count = count, tmp_start = start;
181 BUG_ON(!q->irq_ptr->sch_token);
184 nr += q->irq_ptr->nr_input_qs;
186 ccq = do_sqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count);
187 rc = qdio_check_ccq(q, ccq);
189 QDIO_DBF_TEXT5(1, trace, "sqAGAIN");
193 QDIO_DBF_TEXT3(1, trace, "sqberr");
194 sprintf(dbf_text, "%2x,%2x", count, tmp_count);
195 QDIO_DBF_TEXT3(1, trace, dbf_text);
196 sprintf(dbf_text, "%d,%d", ccq, nr);
197 QDIO_DBF_TEXT3(1, trace, dbf_text);
199 q->handler(q->irq_ptr->cdev,
200 QDIO_ERROR_ACTIVATE_CHECK_CONDITION,
201 0, -1, -1, q->irq_ptr->int_parm);
205 return count - tmp_count;
208 /* returns number of examined buffers and their common state in *state */
209 static inline int get_buf_states(struct qdio_q *q, unsigned int bufnr,
210 unsigned char *state, unsigned int count)
212 unsigned char __state = 0;
215 BUG_ON(bufnr > QDIO_MAX_BUFFERS_MASK);
216 BUG_ON(count > QDIO_MAX_BUFFERS_PER_Q);
219 return qdio_do_eqbs(q, state, bufnr, count);
221 for (i = 0; i < count; i++) {
223 __state = q->slsb.val[bufnr];
224 else if (q->slsb.val[bufnr] != __state)
226 bufnr = next_buf(bufnr);
232 inline int get_buf_state(struct qdio_q *q, unsigned int bufnr,
233 unsigned char *state)
235 return get_buf_states(q, bufnr, state, 1);
238 /* wrap-around safe setting of slsb states, returns number of changed buffers */
239 static inline int set_buf_states(struct qdio_q *q, int bufnr,
240 unsigned char state, int count)
244 BUG_ON(bufnr > QDIO_MAX_BUFFERS_MASK);
245 BUG_ON(count > QDIO_MAX_BUFFERS_PER_Q);
248 return qdio_do_sqbs(q, state, bufnr, count);
250 for (i = 0; i < count; i++) {
251 xchg(&q->slsb.val[bufnr], state);
252 bufnr = next_buf(bufnr);
257 static inline int set_buf_state(struct qdio_q *q, int bufnr,
260 return set_buf_states(q, bufnr, state, 1);
263 /* set slsb states to initial state */
264 void qdio_init_buf_states(struct qdio_irq *irq_ptr)
269 for_each_input_queue(irq_ptr, q, i)
270 set_buf_states(q, 0, SLSB_P_INPUT_NOT_INIT,
271 QDIO_MAX_BUFFERS_PER_Q);
272 for_each_output_queue(irq_ptr, q, i)
273 set_buf_states(q, 0, SLSB_P_OUTPUT_NOT_INIT,
274 QDIO_MAX_BUFFERS_PER_Q);
277 static int qdio_siga_sync(struct qdio_q *q, unsigned int output,
282 if (!need_siga_sync(q))
285 qdio_perf_stat_inc(&perf_stats.siga_sync);
287 cc = do_siga_sync(q->irq_ptr->schid, output, input);
289 QDIO_DBF_TEXT4(0, trace, "sigasync");
290 QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
291 QDIO_DBF_HEX3(0, trace, &cc, sizeof(int *));
296 inline int qdio_siga_sync_q(struct qdio_q *q)
299 return qdio_siga_sync(q, 0, q->mask);
301 return qdio_siga_sync(q, q->mask, 0);
304 static inline int qdio_siga_sync_out(struct qdio_q *q)
306 return qdio_siga_sync(q, ~0U, 0);
309 static inline int qdio_siga_sync_all(struct qdio_q *q)
311 return qdio_siga_sync(q, ~0U, ~0U);
314 static inline int qdio_do_siga_output(struct qdio_q *q, unsigned int *busy_bit)
320 schid = *((u32 *)&q->irq_ptr->schid);
322 schid = q->irq_ptr->sch_token;
325 return do_siga_output(schid, q->mask, busy_bit, fc);
328 static int qdio_siga_output(struct qdio_q *q)
334 QDIO_DBF_TEXT5(0, trace, "sigaout");
335 QDIO_DBF_HEX5(0, trace, &q, sizeof(void *));
337 qdio_perf_stat_inc(&perf_stats.siga_out);
339 cc = qdio_do_siga_output(q, &busy_bit);
340 if (queue_type(q) == QDIO_IQDIO_QFMT && cc == 2 && busy_bit) {
342 start_time = get_usecs();
343 else if ((get_usecs() - start_time) < QDIO_BUSY_BIT_PATIENCE)
347 if (cc == 2 && busy_bit)
348 cc |= QDIO_ERROR_SIGA_BUSY;
350 QDIO_DBF_HEX3(0, trace, &cc, sizeof(int *));
354 static inline int qdio_siga_input(struct qdio_q *q)
358 QDIO_DBF_TEXT4(0, trace, "sigain");
359 QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
361 qdio_perf_stat_inc(&perf_stats.siga_in);
363 cc = do_siga_input(q->irq_ptr->schid, q->mask);
365 QDIO_DBF_HEX3(0, trace, &cc, sizeof(int *));
369 /* called from thinint inbound handler */
370 void qdio_sync_after_thinint(struct qdio_q *q)
372 if (pci_out_supported(q)) {
373 if (need_siga_sync_thinint(q))
374 qdio_siga_sync_all(q);
375 else if (need_siga_sync_out_thinint(q))
376 qdio_siga_sync_out(q);
381 inline void qdio_stop_polling(struct qdio_q *q)
383 spin_lock_bh(&q->u.in.lock);
384 if (!q->u.in.polling) {
385 spin_unlock_bh(&q->u.in.lock);
389 qdio_perf_stat_inc(&perf_stats.debug_stop_polling);
391 /* show the card that we are not polling anymore */
392 set_buf_state(q, q->last_move_ftc, SLSB_P_INPUT_NOT_INIT);
393 spin_unlock_bh(&q->u.in.lock);
396 static void announce_buffer_error(struct qdio_q *q)
401 QDIO_DBF_TEXT3(1, trace, "inperr");
403 QDIO_DBF_TEXT3(0, trace, "outperr");
405 sprintf(dbf_text, "%x-%x-%x", q->first_to_check,
406 q->sbal[q->first_to_check]->element[14].flags,
407 q->sbal[q->first_to_check]->element[15].flags);
408 QDIO_DBF_TEXT3(1, trace, dbf_text);
409 QDIO_DBF_HEX2(1, trace, q->sbal[q->first_to_check], 256);
411 q->qdio_error = QDIO_ERROR_SLSB_STATE;
414 static int get_inbound_buffer_frontier(struct qdio_q *q)
420 * If we still poll don't update last_move_ftc, keep the
421 * previously ACK buffer there.
423 if (!q->u.in.polling)
424 q->last_move_ftc = q->first_to_check;
427 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
430 count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
431 stop = add_buf(q->first_to_check, count);
434 * No siga sync here, as a PCI or we after a thin interrupt
435 * will sync the queues.
438 /* need to set count to 1 for non-qebsm */
443 if (q->first_to_check == stop)
446 count = get_buf_states(q, q->first_to_check, &state, count);
451 case SLSB_P_INPUT_PRIMED:
452 QDIO_DBF_TEXT5(0, trace, "inptprim");
455 * Only ACK the first buffer. The ACK will be removed in
459 state = SLSB_P_INPUT_NOT_INIT;
462 state = SLSB_P_INPUT_ACK;
464 set_buf_state(q, q->first_to_check, state);
467 * Need to change all PRIMED buffers to NOT_INIT, otherwise
468 * we're loosing initiative in the thinint code.
471 set_buf_states(q, next_buf(q->first_to_check),
472 SLSB_P_INPUT_NOT_INIT, count - 1);
475 * No siga-sync needed for non-qebsm here, as the inbound queue
476 * will be synced on the next siga-r, resp.
477 * tiqdio_is_inbound_q_done will do the siga-sync.
479 q->first_to_check = add_buf(q->first_to_check, count);
480 atomic_sub(count, &q->nr_buf_used);
482 case SLSB_P_INPUT_ERROR:
483 announce_buffer_error(q);
484 /* process the buffer, the upper layer will take care of it */
485 q->first_to_check = add_buf(q->first_to_check, count);
486 atomic_sub(count, &q->nr_buf_used);
488 case SLSB_CU_INPUT_EMPTY:
489 case SLSB_P_INPUT_NOT_INIT:
490 case SLSB_P_INPUT_ACK:
491 QDIO_DBF_TEXT5(0, trace, "inpnipro");
497 QDIO_DBF_HEX4(0, trace, &q->first_to_check, sizeof(int));
498 return q->first_to_check;
501 int qdio_inbound_q_moved(struct qdio_q *q)
505 bufnr = get_inbound_buffer_frontier(q);
507 if ((bufnr != q->last_move_ftc) || q->qdio_error) {
508 if (!need_siga_sync(q) && !pci_out_supported(q))
509 q->u.in.timestamp = get_usecs();
511 QDIO_DBF_TEXT4(0, trace, "inhasmvd");
512 QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
518 static int qdio_inbound_q_done(struct qdio_q *q)
521 #ifdef CONFIG_QDIO_DEBUG
525 if (!atomic_read(&q->nr_buf_used))
529 * We need that one for synchronization with the adapter, as it
530 * does a kind of PCI avoidance.
534 get_buf_state(q, q->first_to_check, &state);
535 if (state == SLSB_P_INPUT_PRIMED)
536 /* we got something to do */
539 /* on VM, we don't poll, so the q is always done here */
540 if (need_siga_sync(q) || pci_out_supported(q))
544 * At this point we know, that inbound first_to_check
545 * has (probably) not moved (see qdio_inbound_processing).
547 if (get_usecs() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) {
548 #ifdef CONFIG_QDIO_DEBUG
549 QDIO_DBF_TEXT4(0, trace, "inqisdon");
550 QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
551 sprintf(dbf_text, "pf%02x", q->first_to_check);
552 QDIO_DBF_TEXT4(0, trace, dbf_text);
553 #endif /* CONFIG_QDIO_DEBUG */
556 #ifdef CONFIG_QDIO_DEBUG
557 QDIO_DBF_TEXT4(0, trace, "inqisntd");
558 QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
559 sprintf(dbf_text, "pf%02x", q->first_to_check);
560 QDIO_DBF_TEXT4(0, trace, dbf_text);
561 #endif /* CONFIG_QDIO_DEBUG */
566 void qdio_kick_inbound_handler(struct qdio_q *q)
568 int count, start, end;
569 #ifdef CONFIG_QDIO_DEBUG
573 qdio_perf_stat_inc(&perf_stats.inbound_handler);
575 start = q->first_to_kick;
576 end = q->first_to_check;
580 count = end + QDIO_MAX_BUFFERS_PER_Q - start;
582 #ifdef CONFIG_QDIO_DEBUG
583 sprintf(dbf_text, "s=%2xc=%2x", start, count);
584 QDIO_DBF_TEXT4(0, trace, dbf_text);
585 #endif /* CONFIG_QDIO_DEBUG */
587 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
590 q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr,
591 start, count, q->irq_ptr->int_parm);
593 /* for the next time */
594 q->first_to_kick = q->first_to_check;
598 static void __qdio_inbound_processing(struct qdio_q *q)
600 qdio_perf_stat_inc(&perf_stats.tasklet_inbound);
602 if (!qdio_inbound_q_moved(q))
605 qdio_kick_inbound_handler(q);
607 if (!qdio_inbound_q_done(q))
608 /* means poll time is not yet over */
611 qdio_stop_polling(q);
613 * We need to check again to not lose initiative after
614 * resetting the ACK state.
616 if (!qdio_inbound_q_done(q))
620 /* inbound tasklet */
621 void qdio_inbound_processing(unsigned long data)
623 struct qdio_q *q = (struct qdio_q *)data;
624 __qdio_inbound_processing(q);
627 static int get_outbound_buffer_frontier(struct qdio_q *q)
632 if (((queue_type(q) != QDIO_IQDIO_QFMT) && !pci_out_supported(q)) ||
633 (queue_type(q) == QDIO_IQDIO_QFMT && multicast_outbound(q)))
637 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
640 count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
641 stop = add_buf(q->first_to_check, count);
643 /* need to set count to 1 for non-qebsm */
648 if (q->first_to_check == stop)
649 return q->first_to_check;
651 count = get_buf_states(q, q->first_to_check, &state, count);
653 return q->first_to_check;
656 case SLSB_P_OUTPUT_EMPTY:
657 /* the adapter got it */
658 QDIO_DBF_TEXT5(0, trace, "outpempt");
660 atomic_sub(count, &q->nr_buf_used);
661 q->first_to_check = add_buf(q->first_to_check, count);
663 * We fetch all buffer states at once. get_buf_states may
664 * return count < stop. For QEBSM we do not loop.
669 case SLSB_P_OUTPUT_ERROR:
670 announce_buffer_error(q);
671 /* process the buffer, the upper layer will take care of it */
672 q->first_to_check = add_buf(q->first_to_check, count);
673 atomic_sub(count, &q->nr_buf_used);
675 case SLSB_CU_OUTPUT_PRIMED:
676 /* the adapter has not fetched the output yet */
677 QDIO_DBF_TEXT5(0, trace, "outpprim");
679 case SLSB_P_OUTPUT_NOT_INIT:
680 case SLSB_P_OUTPUT_HALTED:
685 return q->first_to_check;
688 /* all buffers processed? */
689 static inline int qdio_outbound_q_done(struct qdio_q *q)
691 return atomic_read(&q->nr_buf_used) == 0;
694 static inline int qdio_outbound_q_moved(struct qdio_q *q)
698 bufnr = get_outbound_buffer_frontier(q);
700 if ((bufnr != q->last_move_ftc) || q->qdio_error) {
701 q->last_move_ftc = bufnr;
702 QDIO_DBF_TEXT4(0, trace, "oqhasmvd");
703 QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
710 * VM could present us cc=2 and busy bit set on SIGA-write
711 * during reconfiguration of their Guest LAN (only in iqdio mode,
712 * otherwise qdio is asynchronous and cc=2 and busy bit there will take
713 * the queues down immediately).
715 * Therefore qdio_siga_output will try for a short time constantly,
716 * if such a condition occurs. If it doesn't change, it will
717 * increase the busy_siga_counter and save the timestamp, and
718 * schedule the queue for later processing. qdio_outbound_processing
719 * will check out the counter. If non-zero, it will call qdio_kick_outbound_q
720 * as often as the value of the counter. This will attempt further SIGA
721 * instructions. For each successful SIGA, the counter is
722 * decreased, for failing SIGAs the counter remains the same, after
723 * all. After some time of no movement, qdio_kick_outbound_q will
724 * finally fail and reflect corresponding error codes to call
725 * the upper layer module and have it take the queues down.
727 * Note that this is a change from the original HiperSockets design
728 * (saying cc=2 and busy bit means take the queues down), but in
729 * these days Guest LAN didn't exist... excessive cc=2 with busy bit
730 * conditions will still take the queues down, but the threshold is
731 * higher due to the Guest LAN environment.
733 * Called from outbound tasklet and do_QDIO handler.
735 static void qdio_kick_outbound_q(struct qdio_q *q)
738 #ifdef CONFIG_QDIO_DEBUG
741 QDIO_DBF_TEXT5(0, trace, "kickoutq");
742 QDIO_DBF_HEX5(0, trace, &q, sizeof(void *));
743 #endif /* CONFIG_QDIO_DEBUG */
745 if (!need_siga_out(q))
748 rc = qdio_siga_output(q);
751 /* went smooth this time, reset timestamp */
752 q->u.out.timestamp = 0;
754 /* TODO: improve error handling for CC=0 case */
755 #ifdef CONFIG_QDIO_DEBUG
756 QDIO_DBF_TEXT3(0, trace, "cc2reslv");
757 sprintf(dbf_text, "%4x%2x%2x", q->irq_ptr->schid.sch_no, q->nr,
758 atomic_read(&q->u.out.busy_siga_counter));
759 QDIO_DBF_TEXT3(0, trace, dbf_text);
760 #endif /* CONFIG_QDIO_DEBUG */
762 /* cc=2 and busy bit */
763 case (2 | QDIO_ERROR_SIGA_BUSY):
764 atomic_inc(&q->u.out.busy_siga_counter);
766 /* if the last siga was successful, save timestamp here */
767 if (!q->u.out.timestamp)
768 q->u.out.timestamp = get_usecs();
770 /* if we're in time, don't touch qdio_error */
771 if (get_usecs() - q->u.out.timestamp < QDIO_BUSY_BIT_GIVE_UP) {
772 tasklet_schedule(&q->tasklet);
775 QDIO_DBF_TEXT2(0, trace, "cc2REPRT");
776 #ifdef CONFIG_QDIO_DEBUG
777 sprintf(dbf_text, "%4x%2x%2x", q->irq_ptr->schid.sch_no, q->nr,
778 atomic_read(&q->u.out.busy_siga_counter));
779 QDIO_DBF_TEXT3(0, trace, dbf_text);
780 #endif /* CONFIG_QDIO_DEBUG */
782 /* for plain cc=1, 2 or 3 */
787 static void qdio_kick_outbound_handler(struct qdio_q *q)
789 int start, end, count;
790 #ifdef CONFIG_QDIO_DEBUG
794 start = q->first_to_kick;
795 end = q->last_move_ftc;
799 count = end + QDIO_MAX_BUFFERS_PER_Q - start;
801 #ifdef CONFIG_QDIO_DEBUG
802 QDIO_DBF_TEXT4(0, trace, "kickouth");
803 QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
805 sprintf(dbf_text, "s=%2xc=%2x", start, count);
806 QDIO_DBF_TEXT4(0, trace, dbf_text);
807 #endif /* CONFIG_QDIO_DEBUG */
809 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
812 q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr, start, count,
813 q->irq_ptr->int_parm);
815 /* for the next time: */
816 q->first_to_kick = q->last_move_ftc;
820 static void __qdio_outbound_processing(struct qdio_q *q)
824 qdio_perf_stat_inc(&perf_stats.tasklet_outbound);
826 /* see comment in qdio_kick_outbound_q */
827 siga_attempts = atomic_read(&q->u.out.busy_siga_counter);
828 while (siga_attempts--) {
829 atomic_dec(&q->u.out.busy_siga_counter);
830 qdio_kick_outbound_q(q);
833 BUG_ON(atomic_read(&q->nr_buf_used) < 0);
835 if (qdio_outbound_q_moved(q))
836 qdio_kick_outbound_handler(q);
838 if (queue_type(q) == QDIO_ZFCP_QFMT) {
839 if (!pci_out_supported(q) && !qdio_outbound_q_done(q))
840 tasklet_schedule(&q->tasklet);
844 /* bail out for HiperSockets unicast queues */
845 if (queue_type(q) == QDIO_IQDIO_QFMT && !multicast_outbound(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 multicast. Make sure buffer switch from PRIMED to
854 * EMPTY is noticed and outbound_handler is called after some time.
856 if (qdio_outbound_q_done(q))
857 del_timer(&q->u.out.timer);
859 if (!timer_pending(&q->u.out.timer)) {
860 mod_timer(&q->u.out.timer, jiffies + 10 * HZ);
861 qdio_perf_stat_inc(&perf_stats.debug_tl_out_timer);
866 /* outbound tasklet */
867 void qdio_outbound_processing(unsigned long data)
869 struct qdio_q *q = (struct qdio_q *)data;
870 __qdio_outbound_processing(q);
873 void qdio_outbound_timer(unsigned long data)
875 struct qdio_q *q = (struct qdio_q *)data;
876 tasklet_schedule(&q->tasklet);
879 /* called from thinint inbound tasklet */
880 void qdio_check_outbound_after_thinint(struct qdio_q *q)
885 if (!pci_out_supported(q))
888 for_each_output_queue(q->irq_ptr, out, i)
889 if (!qdio_outbound_q_done(out))
890 tasklet_schedule(&out->tasklet);
893 static inline void qdio_set_state(struct qdio_irq *irq_ptr,
894 enum qdio_irq_states state)
896 #ifdef CONFIG_QDIO_DEBUG
899 QDIO_DBF_TEXT5(0, trace, "newstate");
900 sprintf(dbf_text, "%4x%4x", irq_ptr->schid.sch_no, state);
901 QDIO_DBF_TEXT5(0, trace, dbf_text);
902 #endif /* CONFIG_QDIO_DEBUG */
904 irq_ptr->state = state;
908 static void qdio_irq_check_sense(struct subchannel_id schid, struct irb *irb)
912 if (irb->esw.esw0.erw.cons) {
913 sprintf(dbf_text, "sens%4x", schid.sch_no);
914 QDIO_DBF_TEXT2(1, trace, dbf_text);
915 QDIO_DBF_HEX0(0, trace, irb, 64);
916 QDIO_DBF_HEX0(0, trace, irb->ecw, 64);
920 /* PCI interrupt handler */
921 static void qdio_int_handler_pci(struct qdio_irq *irq_ptr)
926 qdio_perf_stat_inc(&perf_stats.pci_int);
928 for_each_input_queue(irq_ptr, q, i)
929 tasklet_schedule(&q->tasklet);
931 if (!(irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED))
934 for_each_output_queue(irq_ptr, q, i) {
935 if (qdio_outbound_q_done(q))
938 if (!siga_syncs_out_pci(q))
941 tasklet_schedule(&q->tasklet);
945 static void qdio_handle_activate_check(struct ccw_device *cdev,
946 unsigned long intparm, int cstat, int dstat)
948 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
952 QDIO_DBF_TEXT2(1, trace, "ick2");
953 sprintf(dbf_text, "%s", cdev->dev.bus_id);
954 QDIO_DBF_TEXT2(1, trace, dbf_text);
955 QDIO_DBF_HEX2(0, trace, &intparm, sizeof(int));
956 QDIO_DBF_HEX2(0, trace, &dstat, sizeof(int));
957 QDIO_DBF_HEX2(0, trace, &cstat, sizeof(int));
959 if (irq_ptr->nr_input_qs) {
960 q = irq_ptr->input_qs[0];
961 } else if (irq_ptr->nr_output_qs) {
962 q = irq_ptr->output_qs[0];
967 q->handler(q->irq_ptr->cdev, QDIO_ERROR_ACTIVATE_CHECK_CONDITION,
968 0, -1, -1, irq_ptr->int_parm);
970 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
973 static void qdio_call_shutdown(struct work_struct *work)
975 struct ccw_device_private *priv;
976 struct ccw_device *cdev;
978 priv = container_of(work, struct ccw_device_private, kick_work);
980 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
981 put_device(&cdev->dev);
984 static void qdio_int_error(struct ccw_device *cdev)
986 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
988 switch (irq_ptr->state) {
989 case QDIO_IRQ_STATE_INACTIVE:
990 case QDIO_IRQ_STATE_CLEANUP:
991 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
993 case QDIO_IRQ_STATE_ESTABLISHED:
994 case QDIO_IRQ_STATE_ACTIVE:
995 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
996 if (get_device(&cdev->dev)) {
997 /* Can't call shutdown from interrupt context. */
998 PREPARE_WORK(&cdev->private->kick_work,
1000 queue_work(ccw_device_work, &cdev->private->kick_work);
1006 wake_up(&cdev->private->wait_q);
1009 static int qdio_establish_check_errors(struct ccw_device *cdev, int cstat,
1012 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1014 if (cstat || (dstat & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END))) {
1015 QDIO_DBF_TEXT2(1, setup, "eq:ckcon");
1019 if (!(dstat & DEV_STAT_DEV_END)) {
1020 QDIO_DBF_TEXT2(1, setup, "eq:no de");
1024 if (dstat & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) {
1025 QDIO_DBF_TEXT2(1, setup, "eq:badio");
1030 QDIO_DBF_HEX2(0, trace, &cstat, sizeof(int));
1031 QDIO_DBF_HEX2(0, trace, &dstat, sizeof(int));
1032 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
1036 static void qdio_establish_handle_irq(struct ccw_device *cdev, int cstat,
1039 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1042 sprintf(dbf_text, "qehi%4x", cdev->private->schid.sch_no);
1043 QDIO_DBF_TEXT0(0, setup, dbf_text);
1044 QDIO_DBF_TEXT0(0, trace, dbf_text);
1046 if (!qdio_establish_check_errors(cdev, cstat, dstat))
1047 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ESTABLISHED);
1050 /* qdio interrupt handler */
1051 void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
1054 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1058 qdio_perf_stat_inc(&perf_stats.qdio_int);
1060 if (!intparm || !irq_ptr) {
1061 sprintf(dbf_text, "qihd%4x", cdev->private->schid.sch_no);
1062 QDIO_DBF_TEXT2(1, setup, dbf_text);
1067 switch (PTR_ERR(irb)) {
1069 sprintf(dbf_text, "ierr%4x",
1070 cdev->private->schid.sch_no);
1071 QDIO_DBF_TEXT2(1, setup, dbf_text);
1072 qdio_int_error(cdev);
1075 sprintf(dbf_text, "qtoh%4x",
1076 cdev->private->schid.sch_no);
1077 QDIO_DBF_TEXT2(1, setup, dbf_text);
1078 qdio_int_error(cdev);
1085 qdio_irq_check_sense(irq_ptr->schid, irb);
1087 cstat = irb->scsw.cmd.cstat;
1088 dstat = irb->scsw.cmd.dstat;
1090 switch (irq_ptr->state) {
1091 case QDIO_IRQ_STATE_INACTIVE:
1092 qdio_establish_handle_irq(cdev, cstat, dstat);
1095 case QDIO_IRQ_STATE_CLEANUP:
1096 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1099 case QDIO_IRQ_STATE_ESTABLISHED:
1100 case QDIO_IRQ_STATE_ACTIVE:
1101 if (cstat & SCHN_STAT_PCI) {
1102 qdio_int_handler_pci(irq_ptr);
1103 /* no state change so no need to wake up wait_q */
1106 if ((cstat & ~SCHN_STAT_PCI) || dstat) {
1107 qdio_handle_activate_check(cdev, intparm, cstat,
1114 wake_up(&cdev->private->wait_q);
1118 * qdio_get_ssqd_desc - get qdio subchannel description
1119 * @cdev: ccw device to get description for
1121 * Returns a pointer to the saved qdio subchannel description,
1122 * or NULL for not setup qdio devices.
1124 struct qdio_ssqd_desc *qdio_get_ssqd_desc(struct ccw_device *cdev)
1126 struct qdio_irq *irq_ptr;
1128 QDIO_DBF_TEXT0(0, setup, "getssqd");
1130 irq_ptr = cdev->private->qdio_data;
1134 return &irq_ptr->ssqd_desc;
1136 EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc);
1139 * qdio_cleanup - shutdown queues and free data structures
1140 * @cdev: associated ccw device
1141 * @how: use halt or clear to shutdown
1143 * This function calls qdio_shutdown() for @cdev with method @how
1144 * and on success qdio_free() for @cdev.
1146 int qdio_cleanup(struct ccw_device *cdev, int how)
1148 struct qdio_irq *irq_ptr;
1152 irq_ptr = cdev->private->qdio_data;
1156 sprintf(dbf_text, "qcln%4x", irq_ptr->schid.sch_no);
1157 QDIO_DBF_TEXT1(0, trace, dbf_text);
1158 QDIO_DBF_TEXT0(0, setup, dbf_text);
1160 rc = qdio_shutdown(cdev, how);
1162 rc = qdio_free(cdev);
1165 EXPORT_SYMBOL_GPL(qdio_cleanup);
1167 static void qdio_shutdown_queues(struct ccw_device *cdev)
1169 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1173 for_each_input_queue(irq_ptr, q, i)
1174 tasklet_disable(&q->tasklet);
1176 for_each_output_queue(irq_ptr, q, i) {
1177 tasklet_disable(&q->tasklet);
1178 del_timer(&q->u.out.timer);
1183 * qdio_shutdown - shut down a qdio subchannel
1184 * @cdev: associated ccw device
1185 * @how: use halt or clear to shutdown
1187 int qdio_shutdown(struct ccw_device *cdev, int how)
1189 struct qdio_irq *irq_ptr;
1191 unsigned long flags;
1194 irq_ptr = cdev->private->qdio_data;
1198 mutex_lock(&irq_ptr->setup_mutex);
1200 * Subchannel was already shot down. We cannot prevent being called
1201 * twice since cio may trigger a shutdown asynchronously.
1203 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1204 mutex_unlock(&irq_ptr->setup_mutex);
1208 sprintf(dbf_text, "qsqs%4x", irq_ptr->schid.sch_no);
1209 QDIO_DBF_TEXT1(0, trace, dbf_text);
1210 QDIO_DBF_TEXT0(0, setup, dbf_text);
1212 tiqdio_remove_input_queues(irq_ptr);
1213 qdio_shutdown_queues(cdev);
1214 qdio_shutdown_debug_entries(irq_ptr, cdev);
1216 /* cleanup subchannel */
1217 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1219 if (how & QDIO_FLAG_CLEANUP_USING_CLEAR)
1220 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
1222 /* default behaviour is halt */
1223 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
1225 sprintf(dbf_text, "sher%4x", irq_ptr->schid.sch_no);
1226 QDIO_DBF_TEXT0(0, setup, dbf_text);
1227 sprintf(dbf_text, "rc=%d", rc);
1228 QDIO_DBF_TEXT0(0, setup, dbf_text);
1232 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
1233 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1234 wait_event_interruptible_timeout(cdev->private->wait_q,
1235 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
1236 irq_ptr->state == QDIO_IRQ_STATE_ERR,
1238 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1241 qdio_shutdown_thinint(irq_ptr);
1243 /* restore interrupt handler */
1244 if ((void *)cdev->handler == (void *)qdio_int_handler)
1245 cdev->handler = irq_ptr->orig_handler;
1246 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1248 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1249 mutex_unlock(&irq_ptr->setup_mutex);
1250 module_put(THIS_MODULE);
1255 EXPORT_SYMBOL_GPL(qdio_shutdown);
1258 * qdio_free - free data structures for a qdio subchannel
1259 * @cdev: associated ccw device
1261 int qdio_free(struct ccw_device *cdev)
1263 struct qdio_irq *irq_ptr;
1266 irq_ptr = cdev->private->qdio_data;
1270 mutex_lock(&irq_ptr->setup_mutex);
1272 sprintf(dbf_text, "qfqs%4x", irq_ptr->schid.sch_no);
1273 QDIO_DBF_TEXT1(0, trace, dbf_text);
1274 QDIO_DBF_TEXT0(0, setup, dbf_text);
1276 cdev->private->qdio_data = NULL;
1277 mutex_unlock(&irq_ptr->setup_mutex);
1279 qdio_release_memory(irq_ptr);
1282 EXPORT_SYMBOL_GPL(qdio_free);
1285 * qdio_initialize - allocate and establish queues for a qdio subchannel
1286 * @init_data: initialization data
1288 * This function first allocates queues via qdio_allocate() and on success
1289 * establishes them via qdio_establish().
1291 int qdio_initialize(struct qdio_initialize *init_data)
1296 sprintf(dbf_text, "qini%4x", init_data->cdev->private->schid.sch_no);
1297 QDIO_DBF_TEXT0(0, setup, dbf_text);
1298 QDIO_DBF_TEXT0(0, trace, dbf_text);
1300 rc = qdio_allocate(init_data);
1304 rc = qdio_establish(init_data);
1306 qdio_free(init_data->cdev);
1309 EXPORT_SYMBOL_GPL(qdio_initialize);
1312 * qdio_allocate - allocate qdio queues and associated data
1313 * @init_data: initialization data
1315 int qdio_allocate(struct qdio_initialize *init_data)
1317 struct qdio_irq *irq_ptr;
1320 sprintf(dbf_text, "qalc%4x", init_data->cdev->private->schid.sch_no);
1321 QDIO_DBF_TEXT0(0, setup, dbf_text);
1322 QDIO_DBF_TEXT0(0, trace, dbf_text);
1324 if ((init_data->no_input_qs && !init_data->input_handler) ||
1325 (init_data->no_output_qs && !init_data->output_handler))
1328 if ((init_data->no_input_qs > QDIO_MAX_QUEUES_PER_IRQ) ||
1329 (init_data->no_output_qs > QDIO_MAX_QUEUES_PER_IRQ))
1332 if ((!init_data->input_sbal_addr_array) ||
1333 (!init_data->output_sbal_addr_array))
1336 qdio_allocate_do_dbf(init_data);
1338 /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */
1339 irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1342 QDIO_DBF_TEXT0(0, setup, "irq_ptr:");
1343 QDIO_DBF_HEX0(0, setup, &irq_ptr, sizeof(void *));
1345 mutex_init(&irq_ptr->setup_mutex);
1348 * Allocate a page for the chsc calls in qdio_establish.
1349 * Must be pre-allocated since a zfcp recovery will call
1350 * qdio_establish. In case of low memory and swap on a zfcp disk
1351 * we may not be able to allocate memory otherwise.
1353 irq_ptr->chsc_page = get_zeroed_page(GFP_KERNEL);
1354 if (!irq_ptr->chsc_page)
1357 /* qdr is used in ccw1.cda which is u32 */
1358 irq_ptr->qdr = (struct qdr *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1361 WARN_ON((unsigned long)irq_ptr->qdr & 0xfff);
1363 QDIO_DBF_TEXT0(0, setup, "qdr:");
1364 QDIO_DBF_HEX0(0, setup, &irq_ptr->qdr, sizeof(void *));
1366 if (qdio_allocate_qs(irq_ptr, init_data->no_input_qs,
1367 init_data->no_output_qs))
1370 init_data->cdev->private->qdio_data = irq_ptr;
1371 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1374 qdio_release_memory(irq_ptr);
1378 EXPORT_SYMBOL_GPL(qdio_allocate);
1381 * qdio_establish - establish queues on a qdio subchannel
1382 * @init_data: initialization data
1384 int qdio_establish(struct qdio_initialize *init_data)
1387 struct qdio_irq *irq_ptr;
1388 struct ccw_device *cdev = init_data->cdev;
1389 unsigned long saveflags;
1392 irq_ptr = cdev->private->qdio_data;
1396 if (cdev->private->state != DEV_STATE_ONLINE)
1399 if (!try_module_get(THIS_MODULE))
1402 sprintf(dbf_text, "qest%4x", cdev->private->schid.sch_no);
1403 QDIO_DBF_TEXT0(0, setup, dbf_text);
1404 QDIO_DBF_TEXT0(0, trace, dbf_text);
1406 mutex_lock(&irq_ptr->setup_mutex);
1407 qdio_setup_irq(init_data);
1409 rc = qdio_establish_thinint(irq_ptr);
1411 mutex_unlock(&irq_ptr->setup_mutex);
1412 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1417 irq_ptr->ccw.cmd_code = irq_ptr->equeue.cmd;
1418 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1419 irq_ptr->ccw.count = irq_ptr->equeue.count;
1420 irq_ptr->ccw.cda = (u32)((addr_t)irq_ptr->qdr);
1422 spin_lock_irqsave(get_ccwdev_lock(cdev), saveflags);
1423 ccw_device_set_options_mask(cdev, 0);
1425 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ESTABLISH, 0, 0);
1427 sprintf(dbf_text, "eq:io%4x", irq_ptr->schid.sch_no);
1428 QDIO_DBF_TEXT2(1, setup, dbf_text);
1429 sprintf(dbf_text, "eq:rc%4x", rc);
1430 QDIO_DBF_TEXT2(1, setup, dbf_text);
1432 spin_unlock_irqrestore(get_ccwdev_lock(cdev), saveflags);
1435 mutex_unlock(&irq_ptr->setup_mutex);
1436 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1440 wait_event_interruptible_timeout(cdev->private->wait_q,
1441 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
1442 irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ);
1444 if (irq_ptr->state != QDIO_IRQ_STATE_ESTABLISHED) {
1445 mutex_unlock(&irq_ptr->setup_mutex);
1446 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1450 qdio_setup_ssqd_info(irq_ptr);
1451 sprintf(dbf_text, "qib ac%2x", irq_ptr->qib.ac);
1452 QDIO_DBF_TEXT2(0, setup, dbf_text);
1454 /* qebsm is now setup if available, initialize buffer states */
1455 qdio_init_buf_states(irq_ptr);
1457 mutex_unlock(&irq_ptr->setup_mutex);
1458 qdio_print_subchannel_info(irq_ptr, cdev);
1459 qdio_setup_debug_entries(irq_ptr, cdev);
1462 EXPORT_SYMBOL_GPL(qdio_establish);
1465 * qdio_activate - activate queues on a qdio subchannel
1466 * @cdev: associated cdev
1468 int qdio_activate(struct ccw_device *cdev)
1470 struct qdio_irq *irq_ptr;
1472 unsigned long saveflags;
1475 irq_ptr = cdev->private->qdio_data;
1479 if (cdev->private->state != DEV_STATE_ONLINE)
1482 mutex_lock(&irq_ptr->setup_mutex);
1483 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1488 sprintf(dbf_text, "qact%4x", irq_ptr->schid.sch_no);
1489 QDIO_DBF_TEXT2(0, setup, dbf_text);
1490 QDIO_DBF_TEXT2(0, trace, dbf_text);
1492 irq_ptr->ccw.cmd_code = irq_ptr->aqueue.cmd;
1493 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1494 irq_ptr->ccw.count = irq_ptr->aqueue.count;
1495 irq_ptr->ccw.cda = 0;
1497 spin_lock_irqsave(get_ccwdev_lock(cdev), saveflags);
1498 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
1500 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ACTIVATE,
1501 0, DOIO_DENY_PREFETCH);
1503 sprintf(dbf_text, "aq:io%4x", irq_ptr->schid.sch_no);
1504 QDIO_DBF_TEXT2(1, setup, dbf_text);
1505 sprintf(dbf_text, "aq:rc%4x", rc);
1506 QDIO_DBF_TEXT2(1, setup, dbf_text);
1508 spin_unlock_irqrestore(get_ccwdev_lock(cdev), saveflags);
1513 if (is_thinint_irq(irq_ptr))
1514 tiqdio_add_input_queues(irq_ptr);
1516 /* wait for subchannel to become active */
1519 switch (irq_ptr->state) {
1520 case QDIO_IRQ_STATE_STOPPED:
1521 case QDIO_IRQ_STATE_ERR:
1522 mutex_unlock(&irq_ptr->setup_mutex);
1523 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1526 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
1530 mutex_unlock(&irq_ptr->setup_mutex);
1533 EXPORT_SYMBOL_GPL(qdio_activate);
1535 static inline int buf_in_between(int bufnr, int start, int count)
1537 int end = add_buf(start, count);
1540 if (bufnr >= start && bufnr < end)
1546 /* wrap-around case */
1547 if ((bufnr >= start && bufnr <= QDIO_MAX_BUFFERS_PER_Q) ||
1555 * handle_inbound - reset processed input buffers
1556 * @q: queue containing the buffers
1558 * @bufnr: first buffer to process
1559 * @count: how many buffers are emptied
1561 static void handle_inbound(struct qdio_q *q, unsigned int callflags,
1562 int bufnr, int count)
1564 unsigned long flags;
1568 * do_QDIO could run in parallel with the queue tasklet so the
1569 * upper-layer programm could empty the ACK'ed buffer here.
1570 * If that happens we must clear the polling flag, otherwise
1571 * qdio_stop_polling() could set the buffer to NOT_INIT after
1572 * it was set to EMPTY which would kill us.
1574 spin_lock_irqsave(&q->u.in.lock, flags);
1575 if (q->u.in.polling)
1576 if (buf_in_between(q->last_move_ftc, bufnr, count))
1577 q->u.in.polling = 0;
1579 count = set_buf_states(q, bufnr, SLSB_CU_INPUT_EMPTY, count);
1580 spin_unlock_irqrestore(&q->u.in.lock, flags);
1582 used = atomic_add_return(count, &q->nr_buf_used) - count;
1583 BUG_ON(used + count > QDIO_MAX_BUFFERS_PER_Q);
1585 /* no need to signal as long as the adapter had free buffers */
1589 if (need_siga_in(q)) {
1590 rc = qdio_siga_input(q);
1597 * handle_outbound - process filled outbound buffers
1598 * @q: queue containing the buffers
1600 * @bufnr: first buffer to process
1601 * @count: how many buffers are filled
1603 static void handle_outbound(struct qdio_q *q, unsigned int callflags,
1604 int bufnr, int count)
1606 unsigned char state;
1609 qdio_perf_stat_inc(&perf_stats.outbound_handler);
1611 count = set_buf_states(q, bufnr, SLSB_CU_OUTPUT_PRIMED, count);
1612 used = atomic_add_return(count, &q->nr_buf_used);
1613 BUG_ON(used > QDIO_MAX_BUFFERS_PER_Q);
1615 if (callflags & QDIO_FLAG_PCI_OUT)
1616 q->u.out.pci_out_enabled = 1;
1618 q->u.out.pci_out_enabled = 0;
1620 if (queue_type(q) == QDIO_IQDIO_QFMT) {
1621 if (multicast_outbound(q))
1622 qdio_kick_outbound_q(q);
1625 * One siga-w per buffer required for unicast
1629 qdio_kick_outbound_q(q);
1633 if (need_siga_sync(q)) {
1634 qdio_siga_sync_q(q);
1638 /* try to fast requeue buffers */
1639 get_buf_state(q, prev_buf(bufnr), &state);
1640 if (state != SLSB_CU_OUTPUT_PRIMED)
1641 qdio_kick_outbound_q(q);
1643 QDIO_DBF_TEXT5(0, trace, "fast-req");
1644 qdio_perf_stat_inc(&perf_stats.fast_requeue);
1647 /* Fixme: could wait forever if called from process context */
1648 tasklet_schedule(&q->tasklet);
1652 * do_QDIO - process input or output buffers
1653 * @cdev: associated ccw_device for the qdio subchannel
1654 * @callflags: input or output and special flags from the program
1655 * @q_nr: queue number
1656 * @bufnr: buffer number
1657 * @count: how many buffers to process
1659 int do_QDIO(struct ccw_device *cdev, unsigned int callflags,
1660 int q_nr, int bufnr, int count)
1662 struct qdio_irq *irq_ptr;
1663 #ifdef CONFIG_QDIO_DEBUG
1666 sprintf(dbf_text, "doQD%04x", cdev->private->schid.sch_no);
1667 QDIO_DBF_TEXT3(0, trace, dbf_text);
1668 #endif /* CONFIG_QDIO_DEBUG */
1670 if ((bufnr > QDIO_MAX_BUFFERS_PER_Q) ||
1671 (count > QDIO_MAX_BUFFERS_PER_Q) ||
1672 (q_nr > QDIO_MAX_QUEUES_PER_IRQ))
1678 irq_ptr = cdev->private->qdio_data;
1682 #ifdef CONFIG_QDIO_DEBUG
1683 if (callflags & QDIO_FLAG_SYNC_INPUT)
1684 QDIO_DBF_HEX3(0, trace, &irq_ptr->input_qs[q_nr],
1687 QDIO_DBF_HEX3(0, trace, &irq_ptr->output_qs[q_nr],
1690 sprintf(dbf_text, "flag%04x", callflags);
1691 QDIO_DBF_TEXT3(0, trace, dbf_text);
1692 sprintf(dbf_text, "qi%02xct%02x", bufnr, count);
1693 QDIO_DBF_TEXT3(0, trace, dbf_text);
1694 #endif /* CONFIG_QDIO_DEBUG */
1696 if (irq_ptr->state != QDIO_IRQ_STATE_ACTIVE)
1699 if (callflags & QDIO_FLAG_SYNC_INPUT)
1700 handle_inbound(irq_ptr->input_qs[q_nr],
1701 callflags, bufnr, count);
1702 else if (callflags & QDIO_FLAG_SYNC_OUTPUT)
1703 handle_outbound(irq_ptr->output_qs[q_nr],
1704 callflags, bufnr, count);
1706 QDIO_DBF_TEXT3(1, trace, "doQD:inv");
1711 EXPORT_SYMBOL_GPL(do_QDIO);
1713 static int __init init_QDIO(void)
1717 rc = qdio_setup_init();
1720 rc = tiqdio_allocate_memory();
1723 rc = qdio_debug_init();
1726 rc = qdio_setup_perf_stats();
1729 rc = tiqdio_register_thinints();
1735 qdio_remove_perf_stats();
1739 tiqdio_free_memory();
1745 static void __exit exit_QDIO(void)
1747 tiqdio_unregister_thinints();
1748 tiqdio_free_memory();
1749 qdio_remove_perf_stats();
1754 module_init(init_QDIO);
1755 module_exit(exit_QDIO);