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)
319 if (q->u.out.use_enh_siga) {
323 schid = *((u32 *)&q->irq_ptr->schid);
325 schid = q->irq_ptr->sch_token;
328 return do_siga_output(schid, q->mask, busy_bit, fc);
331 static int qdio_siga_output(struct qdio_q *q)
338 QDIO_DBF_TEXT5(0, trace, "sigaout");
339 QDIO_DBF_HEX5(0, trace, &q, sizeof(void *));
341 qdio_perf_stat_inc(&perf_stats.siga_out);
343 cc = qdio_do_siga_output(q, &busy_bit);
344 if (queue_type(q) == QDIO_IQDIO_QFMT && cc == 2 && busy_bit) {
345 sprintf(dbf_text, "bb%4x%2x", q->irq_ptr->schid.sch_no, q->nr);
346 QDIO_DBF_TEXT3(0, trace, dbf_text);
349 start_time = get_usecs();
350 else if ((get_usecs() - start_time) < QDIO_BUSY_BIT_PATIENCE)
354 if (cc == 2 && busy_bit)
355 cc |= QDIO_ERROR_SIGA_BUSY;
357 QDIO_DBF_HEX3(0, trace, &cc, sizeof(int *));
361 static inline int qdio_siga_input(struct qdio_q *q)
365 QDIO_DBF_TEXT4(0, trace, "sigain");
366 QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
368 qdio_perf_stat_inc(&perf_stats.siga_in);
370 cc = do_siga_input(q->irq_ptr->schid, q->mask);
372 QDIO_DBF_HEX3(0, trace, &cc, sizeof(int *));
376 /* called from thinint inbound handler */
377 void qdio_sync_after_thinint(struct qdio_q *q)
379 if (pci_out_supported(q)) {
380 if (need_siga_sync_thinint(q))
381 qdio_siga_sync_all(q);
382 else if (need_siga_sync_out_thinint(q))
383 qdio_siga_sync_out(q);
388 inline void qdio_stop_polling(struct qdio_q *q)
390 spin_lock_bh(&q->u.in.lock);
391 if (!q->u.in.polling) {
392 spin_unlock_bh(&q->u.in.lock);
396 qdio_perf_stat_inc(&perf_stats.debug_stop_polling);
398 /* show the card that we are not polling anymore */
399 set_buf_state(q, q->last_move_ftc, SLSB_P_INPUT_NOT_INIT);
400 spin_unlock_bh(&q->u.in.lock);
403 static void announce_buffer_error(struct qdio_q *q)
408 QDIO_DBF_TEXT3(1, trace, "inperr");
410 QDIO_DBF_TEXT3(0, trace, "outperr");
412 sprintf(dbf_text, "%x-%x-%x", q->first_to_check,
413 q->sbal[q->first_to_check]->element[14].flags,
414 q->sbal[q->first_to_check]->element[15].flags);
415 QDIO_DBF_TEXT3(1, trace, dbf_text);
416 QDIO_DBF_HEX2(1, trace, q->sbal[q->first_to_check], 256);
418 q->qdio_error = QDIO_ERROR_SLSB_STATE;
421 static int get_inbound_buffer_frontier(struct qdio_q *q)
427 * If we still poll don't update last_move_ftc, keep the
428 * previously ACK buffer there.
430 if (!q->u.in.polling)
431 q->last_move_ftc = q->first_to_check;
434 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
437 count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
438 stop = add_buf(q->first_to_check, count);
441 * No siga sync here, as a PCI or we after a thin interrupt
442 * will sync the queues.
445 /* need to set count to 1 for non-qebsm */
450 if (q->first_to_check == stop)
453 count = get_buf_states(q, q->first_to_check, &state, count);
458 case SLSB_P_INPUT_PRIMED:
459 QDIO_DBF_TEXT5(0, trace, "inptprim");
462 * Only ACK the first buffer. The ACK will be removed in
466 state = SLSB_P_INPUT_NOT_INIT;
469 state = SLSB_P_INPUT_ACK;
471 set_buf_state(q, q->first_to_check, state);
474 * Need to change all PRIMED buffers to NOT_INIT, otherwise
475 * we're loosing initiative in the thinint code.
478 set_buf_states(q, next_buf(q->first_to_check),
479 SLSB_P_INPUT_NOT_INIT, count - 1);
482 * No siga-sync needed for non-qebsm here, as the inbound queue
483 * will be synced on the next siga-r, resp.
484 * tiqdio_is_inbound_q_done will do the siga-sync.
486 q->first_to_check = add_buf(q->first_to_check, count);
487 atomic_sub(count, &q->nr_buf_used);
489 case SLSB_P_INPUT_ERROR:
490 announce_buffer_error(q);
491 /* process the buffer, the upper layer will take care of it */
492 q->first_to_check = add_buf(q->first_to_check, count);
493 atomic_sub(count, &q->nr_buf_used);
495 case SLSB_CU_INPUT_EMPTY:
496 case SLSB_P_INPUT_NOT_INIT:
497 case SLSB_P_INPUT_ACK:
498 QDIO_DBF_TEXT5(0, trace, "inpnipro");
504 QDIO_DBF_HEX4(0, trace, &q->first_to_check, sizeof(int));
505 return q->first_to_check;
508 int qdio_inbound_q_moved(struct qdio_q *q)
512 bufnr = get_inbound_buffer_frontier(q);
514 if ((bufnr != q->last_move_ftc) || q->qdio_error) {
515 if (!need_siga_sync(q) && !pci_out_supported(q))
516 q->u.in.timestamp = get_usecs();
518 QDIO_DBF_TEXT4(0, trace, "inhasmvd");
519 QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
525 static int qdio_inbound_q_done(struct qdio_q *q)
528 #ifdef CONFIG_QDIO_DEBUG
532 if (!atomic_read(&q->nr_buf_used))
536 * We need that one for synchronization with the adapter, as it
537 * does a kind of PCI avoidance.
541 get_buf_state(q, q->first_to_check, &state);
542 if (state == SLSB_P_INPUT_PRIMED)
543 /* we got something to do */
546 /* on VM, we don't poll, so the q is always done here */
547 if (need_siga_sync(q) || pci_out_supported(q))
551 * At this point we know, that inbound first_to_check
552 * has (probably) not moved (see qdio_inbound_processing).
554 if (get_usecs() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) {
555 #ifdef CONFIG_QDIO_DEBUG
556 QDIO_DBF_TEXT4(0, trace, "inqisdon");
557 QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
558 sprintf(dbf_text, "pf%02x", q->first_to_check);
559 QDIO_DBF_TEXT4(0, trace, dbf_text);
560 #endif /* CONFIG_QDIO_DEBUG */
563 #ifdef CONFIG_QDIO_DEBUG
564 QDIO_DBF_TEXT4(0, trace, "inqisntd");
565 QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
566 sprintf(dbf_text, "pf%02x", q->first_to_check);
567 QDIO_DBF_TEXT4(0, trace, dbf_text);
568 #endif /* CONFIG_QDIO_DEBUG */
573 void qdio_kick_inbound_handler(struct qdio_q *q)
575 int count, start, end;
576 #ifdef CONFIG_QDIO_DEBUG
580 qdio_perf_stat_inc(&perf_stats.inbound_handler);
582 start = q->first_to_kick;
583 end = q->first_to_check;
587 count = end + QDIO_MAX_BUFFERS_PER_Q - start;
589 #ifdef CONFIG_QDIO_DEBUG
590 sprintf(dbf_text, "s=%2xc=%2x", start, count);
591 QDIO_DBF_TEXT4(0, trace, dbf_text);
592 #endif /* CONFIG_QDIO_DEBUG */
594 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
597 q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr,
598 start, count, q->irq_ptr->int_parm);
600 /* for the next time */
601 q->first_to_kick = q->first_to_check;
605 static void __qdio_inbound_processing(struct qdio_q *q)
607 qdio_perf_stat_inc(&perf_stats.tasklet_inbound);
609 if (!qdio_inbound_q_moved(q))
612 qdio_kick_inbound_handler(q);
614 if (!qdio_inbound_q_done(q))
615 /* means poll time is not yet over */
618 qdio_stop_polling(q);
620 * We need to check again to not lose initiative after
621 * resetting the ACK state.
623 if (!qdio_inbound_q_done(q))
627 /* inbound tasklet */
628 void qdio_inbound_processing(unsigned long data)
630 struct qdio_q *q = (struct qdio_q *)data;
631 __qdio_inbound_processing(q);
634 static int get_outbound_buffer_frontier(struct qdio_q *q)
639 if (((queue_type(q) != QDIO_IQDIO_QFMT) && !pci_out_supported(q)) ||
640 (queue_type(q) == QDIO_IQDIO_QFMT && multicast_outbound(q)))
644 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
647 count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
648 stop = add_buf(q->first_to_check, count);
650 /* need to set count to 1 for non-qebsm */
655 if (q->first_to_check == stop)
656 return q->first_to_check;
658 count = get_buf_states(q, q->first_to_check, &state, count);
660 return q->first_to_check;
663 case SLSB_P_OUTPUT_EMPTY:
664 /* the adapter got it */
665 QDIO_DBF_TEXT5(0, trace, "outpempt");
667 atomic_sub(count, &q->nr_buf_used);
668 q->first_to_check = add_buf(q->first_to_check, count);
670 * We fetch all buffer states at once. get_buf_states may
671 * return count < stop. For QEBSM we do not loop.
676 case SLSB_P_OUTPUT_ERROR:
677 announce_buffer_error(q);
678 /* process the buffer, the upper layer will take care of it */
679 q->first_to_check = add_buf(q->first_to_check, count);
680 atomic_sub(count, &q->nr_buf_used);
682 case SLSB_CU_OUTPUT_PRIMED:
683 /* the adapter has not fetched the output yet */
684 QDIO_DBF_TEXT5(0, trace, "outpprim");
686 case SLSB_P_OUTPUT_NOT_INIT:
687 case SLSB_P_OUTPUT_HALTED:
692 return q->first_to_check;
695 /* all buffers processed? */
696 static inline int qdio_outbound_q_done(struct qdio_q *q)
698 return atomic_read(&q->nr_buf_used) == 0;
701 static inline int qdio_outbound_q_moved(struct qdio_q *q)
705 bufnr = get_outbound_buffer_frontier(q);
707 if ((bufnr != q->last_move_ftc) || q->qdio_error) {
708 q->last_move_ftc = bufnr;
709 QDIO_DBF_TEXT4(0, trace, "oqhasmvd");
710 QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
717 * VM could present us cc=2 and busy bit set on SIGA-write
718 * during reconfiguration of their Guest LAN (only in iqdio mode,
719 * otherwise qdio is asynchronous and cc=2 and busy bit there will take
720 * the queues down immediately).
722 * Therefore qdio_siga_output will try for a short time constantly,
723 * if such a condition occurs. If it doesn't change, it will
724 * increase the busy_siga_counter and save the timestamp, and
725 * schedule the queue for later processing. qdio_outbound_processing
726 * will check out the counter. If non-zero, it will call qdio_kick_outbound_q
727 * as often as the value of the counter. This will attempt further SIGA
728 * instructions. For each successful SIGA, the counter is
729 * decreased, for failing SIGAs the counter remains the same, after
730 * all. After some time of no movement, qdio_kick_outbound_q will
731 * finally fail and reflect corresponding error codes to call
732 * the upper layer module and have it take the queues down.
734 * Note that this is a change from the original HiperSockets design
735 * (saying cc=2 and busy bit means take the queues down), but in
736 * these days Guest LAN didn't exist... excessive cc=2 with busy bit
737 * conditions will still take the queues down, but the threshold is
738 * higher due to the Guest LAN environment.
740 * Called from outbound tasklet and do_QDIO handler.
742 static void qdio_kick_outbound_q(struct qdio_q *q)
745 #ifdef CONFIG_QDIO_DEBUG
748 QDIO_DBF_TEXT5(0, trace, "kickoutq");
749 QDIO_DBF_HEX5(0, trace, &q, sizeof(void *));
750 #endif /* CONFIG_QDIO_DEBUG */
752 if (!need_siga_out(q))
755 rc = qdio_siga_output(q);
758 /* TODO: improve error handling for CC=0 case */
759 #ifdef CONFIG_QDIO_DEBUG
760 if (q->u.out.timestamp) {
761 QDIO_DBF_TEXT3(0, trace, "cc2reslv");
762 sprintf(dbf_text, "%4x%2x%2x", q->irq_ptr->schid.sch_no,
764 atomic_read(&q->u.out.busy_siga_counter));
765 QDIO_DBF_TEXT3(0, trace, dbf_text);
767 #endif /* CONFIG_QDIO_DEBUG */
768 /* went smooth this time, reset timestamp */
769 q->u.out.timestamp = 0;
771 /* cc=2 and busy bit */
772 case (2 | QDIO_ERROR_SIGA_BUSY):
773 atomic_inc(&q->u.out.busy_siga_counter);
775 /* if the last siga was successful, save timestamp here */
776 if (!q->u.out.timestamp)
777 q->u.out.timestamp = get_usecs();
779 /* if we're in time, don't touch qdio_error */
780 if (get_usecs() - q->u.out.timestamp < QDIO_BUSY_BIT_GIVE_UP) {
781 tasklet_schedule(&q->tasklet);
784 QDIO_DBF_TEXT2(0, trace, "cc2REPRT");
785 #ifdef CONFIG_QDIO_DEBUG
786 sprintf(dbf_text, "%4x%2x%2x", q->irq_ptr->schid.sch_no, q->nr,
787 atomic_read(&q->u.out.busy_siga_counter));
788 QDIO_DBF_TEXT3(0, trace, dbf_text);
789 #endif /* CONFIG_QDIO_DEBUG */
791 /* for plain cc=1, 2 or 3 */
796 static void qdio_kick_outbound_handler(struct qdio_q *q)
798 int start, end, count;
799 #ifdef CONFIG_QDIO_DEBUG
803 start = q->first_to_kick;
804 end = q->last_move_ftc;
808 count = end + QDIO_MAX_BUFFERS_PER_Q - start;
810 #ifdef CONFIG_QDIO_DEBUG
811 QDIO_DBF_TEXT4(0, trace, "kickouth");
812 QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
814 sprintf(dbf_text, "s=%2xc=%2x", start, count);
815 QDIO_DBF_TEXT4(0, trace, dbf_text);
816 #endif /* CONFIG_QDIO_DEBUG */
818 if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
821 q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr, start, count,
822 q->irq_ptr->int_parm);
824 /* for the next time: */
825 q->first_to_kick = q->last_move_ftc;
829 static void __qdio_outbound_processing(struct qdio_q *q)
833 qdio_perf_stat_inc(&perf_stats.tasklet_outbound);
835 /* see comment in qdio_kick_outbound_q */
836 siga_attempts = atomic_read(&q->u.out.busy_siga_counter);
837 while (siga_attempts--) {
838 atomic_dec(&q->u.out.busy_siga_counter);
839 qdio_kick_outbound_q(q);
842 BUG_ON(atomic_read(&q->nr_buf_used) < 0);
844 if (qdio_outbound_q_moved(q))
845 qdio_kick_outbound_handler(q);
847 if (queue_type(q) == QDIO_ZFCP_QFMT) {
848 if (!pci_out_supported(q) && !qdio_outbound_q_done(q))
849 tasklet_schedule(&q->tasklet);
853 /* bail out for HiperSockets unicast queues */
854 if (queue_type(q) == QDIO_IQDIO_QFMT && !multicast_outbound(q))
857 if ((queue_type(q) == QDIO_IQDIO_QFMT) &&
858 (atomic_read(&q->nr_buf_used)) > QDIO_IQDIO_POLL_LVL) {
859 tasklet_schedule(&q->tasklet);
863 if (q->u.out.pci_out_enabled)
867 * Now we know that queue type is either qeth without pci enabled
868 * or HiperSockets multicast. Make sure buffer switch from PRIMED to
869 * EMPTY is noticed and outbound_handler is called after some time.
871 if (qdio_outbound_q_done(q))
872 del_timer(&q->u.out.timer);
874 if (!timer_pending(&q->u.out.timer)) {
875 mod_timer(&q->u.out.timer, jiffies + 10 * HZ);
876 qdio_perf_stat_inc(&perf_stats.debug_tl_out_timer);
881 /* outbound tasklet */
882 void qdio_outbound_processing(unsigned long data)
884 struct qdio_q *q = (struct qdio_q *)data;
885 __qdio_outbound_processing(q);
888 void qdio_outbound_timer(unsigned long data)
890 struct qdio_q *q = (struct qdio_q *)data;
891 tasklet_schedule(&q->tasklet);
894 /* called from thinint inbound tasklet */
895 void qdio_check_outbound_after_thinint(struct qdio_q *q)
900 if (!pci_out_supported(q))
903 for_each_output_queue(q->irq_ptr, out, i)
904 if (!qdio_outbound_q_done(out))
905 tasklet_schedule(&out->tasklet);
908 static inline void qdio_set_state(struct qdio_irq *irq_ptr,
909 enum qdio_irq_states state)
911 #ifdef CONFIG_QDIO_DEBUG
914 QDIO_DBF_TEXT5(0, trace, "newstate");
915 sprintf(dbf_text, "%4x%4x", irq_ptr->schid.sch_no, state);
916 QDIO_DBF_TEXT5(0, trace, dbf_text);
917 #endif /* CONFIG_QDIO_DEBUG */
919 irq_ptr->state = state;
923 static void qdio_irq_check_sense(struct subchannel_id schid, struct irb *irb)
927 if (irb->esw.esw0.erw.cons) {
928 sprintf(dbf_text, "sens%4x", schid.sch_no);
929 QDIO_DBF_TEXT2(1, trace, dbf_text);
930 QDIO_DBF_HEX0(0, trace, irb, 64);
931 QDIO_DBF_HEX0(0, trace, irb->ecw, 64);
935 /* PCI interrupt handler */
936 static void qdio_int_handler_pci(struct qdio_irq *irq_ptr)
941 qdio_perf_stat_inc(&perf_stats.pci_int);
943 for_each_input_queue(irq_ptr, q, i)
944 tasklet_schedule(&q->tasklet);
946 if (!(irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED))
949 for_each_output_queue(irq_ptr, q, i) {
950 if (qdio_outbound_q_done(q))
953 if (!siga_syncs_out_pci(q))
956 tasklet_schedule(&q->tasklet);
960 static void qdio_handle_activate_check(struct ccw_device *cdev,
961 unsigned long intparm, int cstat, int dstat)
963 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
967 QDIO_DBF_TEXT2(1, trace, "ick2");
968 sprintf(dbf_text, "%s", dev_name(&cdev->dev));
969 QDIO_DBF_TEXT2(1, trace, dbf_text);
970 QDIO_DBF_HEX2(0, trace, &intparm, sizeof(int));
971 QDIO_DBF_HEX2(0, trace, &dstat, sizeof(int));
972 QDIO_DBF_HEX2(0, trace, &cstat, sizeof(int));
974 if (irq_ptr->nr_input_qs) {
975 q = irq_ptr->input_qs[0];
976 } else if (irq_ptr->nr_output_qs) {
977 q = irq_ptr->output_qs[0];
982 q->handler(q->irq_ptr->cdev, QDIO_ERROR_ACTIVATE_CHECK_CONDITION,
983 0, -1, -1, irq_ptr->int_parm);
985 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
988 static void qdio_call_shutdown(struct work_struct *work)
990 struct ccw_device_private *priv;
991 struct ccw_device *cdev;
993 priv = container_of(work, struct ccw_device_private, kick_work);
995 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
996 put_device(&cdev->dev);
999 static void qdio_int_error(struct ccw_device *cdev)
1001 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1003 switch (irq_ptr->state) {
1004 case QDIO_IRQ_STATE_INACTIVE:
1005 case QDIO_IRQ_STATE_CLEANUP:
1006 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
1008 case QDIO_IRQ_STATE_ESTABLISHED:
1009 case QDIO_IRQ_STATE_ACTIVE:
1010 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
1011 if (get_device(&cdev->dev)) {
1012 /* Can't call shutdown from interrupt context. */
1013 PREPARE_WORK(&cdev->private->kick_work,
1014 qdio_call_shutdown);
1015 queue_work(ccw_device_work, &cdev->private->kick_work);
1021 wake_up(&cdev->private->wait_q);
1024 static int qdio_establish_check_errors(struct ccw_device *cdev, int cstat,
1027 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1029 if (cstat || (dstat & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END))) {
1030 QDIO_DBF_TEXT2(1, setup, "eq:ckcon");
1034 if (!(dstat & DEV_STAT_DEV_END)) {
1035 QDIO_DBF_TEXT2(1, setup, "eq:no de");
1039 if (dstat & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) {
1040 QDIO_DBF_TEXT2(1, setup, "eq:badio");
1045 QDIO_DBF_HEX2(0, trace, &cstat, sizeof(int));
1046 QDIO_DBF_HEX2(0, trace, &dstat, sizeof(int));
1047 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
1051 static void qdio_establish_handle_irq(struct ccw_device *cdev, int cstat,
1054 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1057 sprintf(dbf_text, "qehi%4x", cdev->private->schid.sch_no);
1058 QDIO_DBF_TEXT0(0, setup, dbf_text);
1059 QDIO_DBF_TEXT0(0, trace, dbf_text);
1061 if (!qdio_establish_check_errors(cdev, cstat, dstat))
1062 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ESTABLISHED);
1065 /* qdio interrupt handler */
1066 void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
1069 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1073 qdio_perf_stat_inc(&perf_stats.qdio_int);
1075 if (!intparm || !irq_ptr) {
1076 sprintf(dbf_text, "qihd%4x", cdev->private->schid.sch_no);
1077 QDIO_DBF_TEXT2(1, setup, dbf_text);
1082 switch (PTR_ERR(irb)) {
1084 sprintf(dbf_text, "ierr%4x", irq_ptr->schid.sch_no);
1085 QDIO_DBF_TEXT2(1, setup, dbf_text);
1086 qdio_int_error(cdev);
1089 sprintf(dbf_text, "qtoh%4x", irq_ptr->schid.sch_no);
1090 QDIO_DBF_TEXT2(1, setup, dbf_text);
1091 qdio_int_error(cdev);
1098 qdio_irq_check_sense(irq_ptr->schid, irb);
1100 cstat = irb->scsw.cmd.cstat;
1101 dstat = irb->scsw.cmd.dstat;
1103 switch (irq_ptr->state) {
1104 case QDIO_IRQ_STATE_INACTIVE:
1105 qdio_establish_handle_irq(cdev, cstat, dstat);
1108 case QDIO_IRQ_STATE_CLEANUP:
1109 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1112 case QDIO_IRQ_STATE_ESTABLISHED:
1113 case QDIO_IRQ_STATE_ACTIVE:
1114 if (cstat & SCHN_STAT_PCI) {
1115 qdio_int_handler_pci(irq_ptr);
1116 /* no state change so no need to wake up wait_q */
1119 if ((cstat & ~SCHN_STAT_PCI) || dstat) {
1120 qdio_handle_activate_check(cdev, intparm, cstat,
1127 wake_up(&cdev->private->wait_q);
1131 * qdio_get_ssqd_desc - get qdio subchannel description
1132 * @cdev: ccw device to get description for
1134 * Returns a pointer to the saved qdio subchannel description,
1135 * or NULL for not setup qdio devices.
1137 struct qdio_ssqd_desc *qdio_get_ssqd_desc(struct ccw_device *cdev)
1139 struct qdio_irq *irq_ptr;
1142 sprintf(dbf_text, "qssq%4x", cdev->private->schid.sch_no);
1143 QDIO_DBF_TEXT0(0, setup, dbf_text);
1145 irq_ptr = cdev->private->qdio_data;
1149 return &irq_ptr->ssqd_desc;
1151 EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc);
1154 * qdio_cleanup - shutdown queues and free data structures
1155 * @cdev: associated ccw device
1156 * @how: use halt or clear to shutdown
1158 * This function calls qdio_shutdown() for @cdev with method @how
1159 * and on success qdio_free() for @cdev.
1161 int qdio_cleanup(struct ccw_device *cdev, int how)
1163 struct qdio_irq *irq_ptr;
1167 sprintf(dbf_text, "qcln%4x", cdev->private->schid.sch_no);
1168 QDIO_DBF_TEXT0(0, setup, dbf_text);
1170 irq_ptr = cdev->private->qdio_data;
1174 rc = qdio_shutdown(cdev, how);
1176 rc = qdio_free(cdev);
1179 EXPORT_SYMBOL_GPL(qdio_cleanup);
1181 static void qdio_shutdown_queues(struct ccw_device *cdev)
1183 struct qdio_irq *irq_ptr = cdev->private->qdio_data;
1187 for_each_input_queue(irq_ptr, q, i)
1188 tasklet_disable(&q->tasklet);
1190 for_each_output_queue(irq_ptr, q, i) {
1191 tasklet_disable(&q->tasklet);
1192 del_timer(&q->u.out.timer);
1197 * qdio_shutdown - shut down a qdio subchannel
1198 * @cdev: associated ccw device
1199 * @how: use halt or clear to shutdown
1201 int qdio_shutdown(struct ccw_device *cdev, int how)
1203 struct qdio_irq *irq_ptr;
1205 unsigned long flags;
1208 sprintf(dbf_text, "qshu%4x", cdev->private->schid.sch_no);
1209 QDIO_DBF_TEXT0(0, setup, dbf_text);
1211 irq_ptr = cdev->private->qdio_data;
1215 mutex_lock(&irq_ptr->setup_mutex);
1217 * Subchannel was already shot down. We cannot prevent being called
1218 * twice since cio may trigger a shutdown asynchronously.
1220 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1221 mutex_unlock(&irq_ptr->setup_mutex);
1225 tiqdio_remove_input_queues(irq_ptr);
1226 qdio_shutdown_queues(cdev);
1227 qdio_shutdown_debug_entries(irq_ptr, cdev);
1229 /* cleanup subchannel */
1230 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1232 if (how & QDIO_FLAG_CLEANUP_USING_CLEAR)
1233 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
1235 /* default behaviour is halt */
1236 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
1238 sprintf(dbf_text, "sher%4x", irq_ptr->schid.sch_no);
1239 QDIO_DBF_TEXT0(0, setup, dbf_text);
1240 sprintf(dbf_text, "rc=%d", rc);
1241 QDIO_DBF_TEXT0(0, setup, dbf_text);
1245 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
1246 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1247 wait_event_interruptible_timeout(cdev->private->wait_q,
1248 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
1249 irq_ptr->state == QDIO_IRQ_STATE_ERR,
1251 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1254 qdio_shutdown_thinint(irq_ptr);
1256 /* restore interrupt handler */
1257 if ((void *)cdev->handler == (void *)qdio_int_handler)
1258 cdev->handler = irq_ptr->orig_handler;
1259 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1261 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1262 mutex_unlock(&irq_ptr->setup_mutex);
1267 EXPORT_SYMBOL_GPL(qdio_shutdown);
1270 * qdio_free - free data structures for a qdio subchannel
1271 * @cdev: associated ccw device
1273 int qdio_free(struct ccw_device *cdev)
1275 struct qdio_irq *irq_ptr;
1278 sprintf(dbf_text, "qfre%4x", cdev->private->schid.sch_no);
1279 QDIO_DBF_TEXT0(0, setup, dbf_text);
1281 irq_ptr = cdev->private->qdio_data;
1285 mutex_lock(&irq_ptr->setup_mutex);
1286 cdev->private->qdio_data = NULL;
1287 mutex_unlock(&irq_ptr->setup_mutex);
1289 qdio_release_memory(irq_ptr);
1292 EXPORT_SYMBOL_GPL(qdio_free);
1295 * qdio_initialize - allocate and establish queues for a qdio subchannel
1296 * @init_data: initialization data
1298 * This function first allocates queues via qdio_allocate() and on success
1299 * establishes them via qdio_establish().
1301 int qdio_initialize(struct qdio_initialize *init_data)
1306 sprintf(dbf_text, "qini%4x", init_data->cdev->private->schid.sch_no);
1307 QDIO_DBF_TEXT0(0, setup, dbf_text);
1309 rc = qdio_allocate(init_data);
1313 rc = qdio_establish(init_data);
1315 qdio_free(init_data->cdev);
1318 EXPORT_SYMBOL_GPL(qdio_initialize);
1321 * qdio_allocate - allocate qdio queues and associated data
1322 * @init_data: initialization data
1324 int qdio_allocate(struct qdio_initialize *init_data)
1326 struct qdio_irq *irq_ptr;
1329 sprintf(dbf_text, "qalc%4x", init_data->cdev->private->schid.sch_no);
1330 QDIO_DBF_TEXT0(0, setup, dbf_text);
1332 if ((init_data->no_input_qs && !init_data->input_handler) ||
1333 (init_data->no_output_qs && !init_data->output_handler))
1336 if ((init_data->no_input_qs > QDIO_MAX_QUEUES_PER_IRQ) ||
1337 (init_data->no_output_qs > QDIO_MAX_QUEUES_PER_IRQ))
1340 if ((!init_data->input_sbal_addr_array) ||
1341 (!init_data->output_sbal_addr_array))
1344 qdio_allocate_do_dbf(init_data);
1346 /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */
1347 irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1350 QDIO_DBF_TEXT0(0, setup, "irq_ptr:");
1351 QDIO_DBF_HEX0(0, setup, &irq_ptr, sizeof(void *));
1353 mutex_init(&irq_ptr->setup_mutex);
1356 * Allocate a page for the chsc calls in qdio_establish.
1357 * Must be pre-allocated since a zfcp recovery will call
1358 * qdio_establish. In case of low memory and swap on a zfcp disk
1359 * we may not be able to allocate memory otherwise.
1361 irq_ptr->chsc_page = get_zeroed_page(GFP_KERNEL);
1362 if (!irq_ptr->chsc_page)
1365 /* qdr is used in ccw1.cda which is u32 */
1366 irq_ptr->qdr = (struct qdr *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
1369 WARN_ON((unsigned long)irq_ptr->qdr & 0xfff);
1371 QDIO_DBF_TEXT0(0, setup, "qdr:");
1372 QDIO_DBF_HEX0(0, setup, &irq_ptr->qdr, sizeof(void *));
1374 if (qdio_allocate_qs(irq_ptr, init_data->no_input_qs,
1375 init_data->no_output_qs))
1378 init_data->cdev->private->qdio_data = irq_ptr;
1379 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
1382 qdio_release_memory(irq_ptr);
1386 EXPORT_SYMBOL_GPL(qdio_allocate);
1389 * qdio_establish - establish queues on a qdio subchannel
1390 * @init_data: initialization data
1392 int qdio_establish(struct qdio_initialize *init_data)
1395 struct qdio_irq *irq_ptr;
1396 struct ccw_device *cdev = init_data->cdev;
1397 unsigned long saveflags;
1400 sprintf(dbf_text, "qest%4x", cdev->private->schid.sch_no);
1401 QDIO_DBF_TEXT0(0, setup, dbf_text);
1403 irq_ptr = cdev->private->qdio_data;
1407 if (cdev->private->state != DEV_STATE_ONLINE)
1410 mutex_lock(&irq_ptr->setup_mutex);
1411 qdio_setup_irq(init_data);
1413 rc = qdio_establish_thinint(irq_ptr);
1415 mutex_unlock(&irq_ptr->setup_mutex);
1416 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1421 irq_ptr->ccw.cmd_code = irq_ptr->equeue.cmd;
1422 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1423 irq_ptr->ccw.count = irq_ptr->equeue.count;
1424 irq_ptr->ccw.cda = (u32)((addr_t)irq_ptr->qdr);
1426 spin_lock_irqsave(get_ccwdev_lock(cdev), saveflags);
1427 ccw_device_set_options_mask(cdev, 0);
1429 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ESTABLISH, 0, 0);
1431 sprintf(dbf_text, "eq:io%4x", irq_ptr->schid.sch_no);
1432 QDIO_DBF_TEXT2(1, setup, dbf_text);
1433 sprintf(dbf_text, "eq:rc%4x", rc);
1434 QDIO_DBF_TEXT2(1, setup, dbf_text);
1436 spin_unlock_irqrestore(get_ccwdev_lock(cdev), saveflags);
1439 mutex_unlock(&irq_ptr->setup_mutex);
1440 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1444 wait_event_interruptible_timeout(cdev->private->wait_q,
1445 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
1446 irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ);
1448 if (irq_ptr->state != QDIO_IRQ_STATE_ESTABLISHED) {
1449 mutex_unlock(&irq_ptr->setup_mutex);
1450 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1454 qdio_setup_ssqd_info(irq_ptr);
1455 sprintf(dbf_text, "qDmmwc%2x", irq_ptr->ssqd_desc.mmwc);
1456 QDIO_DBF_TEXT2(0, setup, dbf_text);
1457 sprintf(dbf_text, "qib ac%2x", irq_ptr->qib.ac);
1458 QDIO_DBF_TEXT2(0, setup, dbf_text);
1460 /* qebsm is now setup if available, initialize buffer states */
1461 qdio_init_buf_states(irq_ptr);
1463 mutex_unlock(&irq_ptr->setup_mutex);
1464 qdio_print_subchannel_info(irq_ptr, cdev);
1465 qdio_setup_debug_entries(irq_ptr, cdev);
1468 EXPORT_SYMBOL_GPL(qdio_establish);
1471 * qdio_activate - activate queues on a qdio subchannel
1472 * @cdev: associated cdev
1474 int qdio_activate(struct ccw_device *cdev)
1476 struct qdio_irq *irq_ptr;
1478 unsigned long saveflags;
1481 sprintf(dbf_text, "qact%4x", cdev->private->schid.sch_no);
1482 QDIO_DBF_TEXT0(0, setup, dbf_text);
1484 irq_ptr = cdev->private->qdio_data;
1488 if (cdev->private->state != DEV_STATE_ONLINE)
1491 mutex_lock(&irq_ptr->setup_mutex);
1492 if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
1497 irq_ptr->ccw.cmd_code = irq_ptr->aqueue.cmd;
1498 irq_ptr->ccw.flags = CCW_FLAG_SLI;
1499 irq_ptr->ccw.count = irq_ptr->aqueue.count;
1500 irq_ptr->ccw.cda = 0;
1502 spin_lock_irqsave(get_ccwdev_lock(cdev), saveflags);
1503 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
1505 rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ACTIVATE,
1506 0, DOIO_DENY_PREFETCH);
1508 sprintf(dbf_text, "aq:io%4x", irq_ptr->schid.sch_no);
1509 QDIO_DBF_TEXT2(1, setup, dbf_text);
1510 sprintf(dbf_text, "aq:rc%4x", rc);
1511 QDIO_DBF_TEXT2(1, setup, dbf_text);
1513 spin_unlock_irqrestore(get_ccwdev_lock(cdev), saveflags);
1518 if (is_thinint_irq(irq_ptr))
1519 tiqdio_add_input_queues(irq_ptr);
1521 /* wait for subchannel to become active */
1524 switch (irq_ptr->state) {
1525 case QDIO_IRQ_STATE_STOPPED:
1526 case QDIO_IRQ_STATE_ERR:
1527 mutex_unlock(&irq_ptr->setup_mutex);
1528 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
1531 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
1535 mutex_unlock(&irq_ptr->setup_mutex);
1538 EXPORT_SYMBOL_GPL(qdio_activate);
1540 static inline int buf_in_between(int bufnr, int start, int count)
1542 int end = add_buf(start, count);
1545 if (bufnr >= start && bufnr < end)
1551 /* wrap-around case */
1552 if ((bufnr >= start && bufnr <= QDIO_MAX_BUFFERS_PER_Q) ||
1560 * handle_inbound - reset processed input buffers
1561 * @q: queue containing the buffers
1563 * @bufnr: first buffer to process
1564 * @count: how many buffers are emptied
1566 static void handle_inbound(struct qdio_q *q, unsigned int callflags,
1567 int bufnr, int count)
1569 unsigned long flags;
1573 * do_QDIO could run in parallel with the queue tasklet so the
1574 * upper-layer programm could empty the ACK'ed buffer here.
1575 * If that happens we must clear the polling flag, otherwise
1576 * qdio_stop_polling() could set the buffer to NOT_INIT after
1577 * it was set to EMPTY which would kill us.
1579 spin_lock_irqsave(&q->u.in.lock, flags);
1580 if (q->u.in.polling)
1581 if (buf_in_between(q->last_move_ftc, bufnr, count))
1582 q->u.in.polling = 0;
1584 count = set_buf_states(q, bufnr, SLSB_CU_INPUT_EMPTY, count);
1585 spin_unlock_irqrestore(&q->u.in.lock, flags);
1587 used = atomic_add_return(count, &q->nr_buf_used) - count;
1588 BUG_ON(used + count > QDIO_MAX_BUFFERS_PER_Q);
1590 /* no need to signal as long as the adapter had free buffers */
1594 if (need_siga_in(q)) {
1595 rc = qdio_siga_input(q);
1602 * handle_outbound - process filled outbound buffers
1603 * @q: queue containing the buffers
1605 * @bufnr: first buffer to process
1606 * @count: how many buffers are filled
1608 static void handle_outbound(struct qdio_q *q, unsigned int callflags,
1609 int bufnr, int count)
1611 unsigned char state;
1614 qdio_perf_stat_inc(&perf_stats.outbound_handler);
1616 count = set_buf_states(q, bufnr, SLSB_CU_OUTPUT_PRIMED, count);
1617 used = atomic_add_return(count, &q->nr_buf_used);
1618 BUG_ON(used > QDIO_MAX_BUFFERS_PER_Q);
1620 if (callflags & QDIO_FLAG_PCI_OUT)
1621 q->u.out.pci_out_enabled = 1;
1623 q->u.out.pci_out_enabled = 0;
1625 if (queue_type(q) == QDIO_IQDIO_QFMT) {
1626 if (multicast_outbound(q))
1627 qdio_kick_outbound_q(q);
1629 if ((q->irq_ptr->ssqd_desc.mmwc > 1) &&
1631 (count <= q->irq_ptr->ssqd_desc.mmwc)) {
1632 /* exploit enhanced SIGA */
1633 q->u.out.use_enh_siga = 1;
1634 qdio_kick_outbound_q(q);
1637 * One siga-w per buffer required for unicast
1640 q->u.out.use_enh_siga = 0;
1642 qdio_kick_outbound_q(q);
1647 if (need_siga_sync(q)) {
1648 qdio_siga_sync_q(q);
1652 /* try to fast requeue buffers */
1653 get_buf_state(q, prev_buf(bufnr), &state);
1654 if (state != SLSB_CU_OUTPUT_PRIMED)
1655 qdio_kick_outbound_q(q);
1657 QDIO_DBF_TEXT5(0, trace, "fast-req");
1658 qdio_perf_stat_inc(&perf_stats.fast_requeue);
1661 /* Fixme: could wait forever if called from process context */
1662 tasklet_schedule(&q->tasklet);
1666 * do_QDIO - process input or output buffers
1667 * @cdev: associated ccw_device for the qdio subchannel
1668 * @callflags: input or output and special flags from the program
1669 * @q_nr: queue number
1670 * @bufnr: buffer number
1671 * @count: how many buffers to process
1673 int do_QDIO(struct ccw_device *cdev, unsigned int callflags,
1674 int q_nr, int bufnr, int count)
1676 struct qdio_irq *irq_ptr;
1677 #ifdef CONFIG_QDIO_DEBUG
1680 sprintf(dbf_text, "doQD%4x", cdev->private->schid.sch_no);
1681 QDIO_DBF_TEXT3(0, trace, dbf_text);
1682 #endif /* CONFIG_QDIO_DEBUG */
1684 if ((bufnr > QDIO_MAX_BUFFERS_PER_Q) ||
1685 (count > QDIO_MAX_BUFFERS_PER_Q) ||
1686 (q_nr > QDIO_MAX_QUEUES_PER_IRQ))
1692 irq_ptr = cdev->private->qdio_data;
1696 #ifdef CONFIG_QDIO_DEBUG
1697 if (callflags & QDIO_FLAG_SYNC_INPUT)
1698 QDIO_DBF_HEX3(0, trace, &irq_ptr->input_qs[q_nr],
1701 QDIO_DBF_HEX3(0, trace, &irq_ptr->output_qs[q_nr],
1704 sprintf(dbf_text, "flag%04x", callflags);
1705 QDIO_DBF_TEXT3(0, trace, dbf_text);
1706 sprintf(dbf_text, "qi%02xct%02x", bufnr, count);
1707 QDIO_DBF_TEXT3(0, trace, dbf_text);
1708 #endif /* CONFIG_QDIO_DEBUG */
1710 if (irq_ptr->state != QDIO_IRQ_STATE_ACTIVE)
1713 if (callflags & QDIO_FLAG_SYNC_INPUT)
1714 handle_inbound(irq_ptr->input_qs[q_nr],
1715 callflags, bufnr, count);
1716 else if (callflags & QDIO_FLAG_SYNC_OUTPUT)
1717 handle_outbound(irq_ptr->output_qs[q_nr],
1718 callflags, bufnr, count);
1720 QDIO_DBF_TEXT3(1, trace, "doQD:inv");
1725 EXPORT_SYMBOL_GPL(do_QDIO);
1727 static int __init init_QDIO(void)
1731 rc = qdio_setup_init();
1734 rc = tiqdio_allocate_memory();
1737 rc = qdio_debug_init();
1740 rc = qdio_setup_perf_stats();
1743 rc = tiqdio_register_thinints();
1749 qdio_remove_perf_stats();
1753 tiqdio_free_memory();
1759 static void __exit exit_QDIO(void)
1761 tiqdio_unregister_thinints();
1762 tiqdio_free_memory();
1763 qdio_remove_perf_stats();
1768 module_init(init_QDIO);
1769 module_exit(exit_QDIO);