3 * linux/drivers/s390/cio/qdio.c
5 * Linux for S/390 QDIO base support, Hipersocket base support
8 * Copyright 2000,2002 IBM Corporation
9 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
10 * 2.6 cio integration by Cornelia Huck <cornelia.huck@de.ibm.com>
12 * Restriction: only 63 iqdio subchannels would have its own indicator,
13 * after that, subsequent subchannels share one indicator
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <linux/module.h>
34 #include <linux/init.h>
36 #include <linux/slab.h>
37 #include <linux/kernel.h>
38 #include <linux/proc_fs.h>
39 #include <linux/timer.h>
40 #include <linux/mempool.h>
42 #include <asm/ccwdev.h>
44 #include <asm/atomic.h>
45 #include <asm/semaphore.h>
46 #include <asm/timex.h>
48 #include <asm/debug.h>
49 #include <asm/s390_rdev.h>
60 /****************** MODULE PARAMETER VARIABLES ********************/
61 MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>");
62 MODULE_DESCRIPTION("QDIO base support version 2, " \
63 "Copyright 2000 IBM Corporation");
64 MODULE_LICENSE("GPL");
66 /******************** HERE WE GO ***********************************/
68 static const char version[] = "QDIO base support version 2";
70 static int qdio_performance_stats = 0;
71 static int proc_perf_file_registration;
72 static unsigned long i_p_c, i_p_nc, o_p_c, o_p_nc, ii_p_c, ii_p_nc;
73 static struct qdio_perf_stats perf_stats;
75 static int hydra_thinints;
76 static int is_passthrough = 0;
79 static int indicator_used[INDICATORS_PER_CACHELINE];
80 static __u32 * volatile indicators;
81 static __u32 volatile spare_indicator;
82 static atomic_t spare_indicator_usecount;
83 #define QDIO_MEMPOOL_SCSSC_ELEMENTS 2
84 static mempool_t *qdio_mempool_scssc;
86 static debug_info_t *qdio_dbf_setup;
87 static debug_info_t *qdio_dbf_sbal;
88 static debug_info_t *qdio_dbf_trace;
89 static debug_info_t *qdio_dbf_sense;
90 #ifdef CONFIG_QDIO_DEBUG
91 static debug_info_t *qdio_dbf_slsb_out;
92 static debug_info_t *qdio_dbf_slsb_in;
93 #endif /* CONFIG_QDIO_DEBUG */
96 static volatile struct qdio_q *tiq_list=NULL; /* volatile as it could change
97 during a while loop */
98 static DEFINE_SPINLOCK(ttiq_list_lock);
99 static int register_thinint_result;
100 static void tiqdio_tl(unsigned long);
101 static DECLARE_TASKLET(tiqdio_tasklet,tiqdio_tl,0);
103 /* not a macro, as one of the arguments is atomic_read */
105 qdio_min(int a,int b)
113 /***************** SCRUBBER HELPER ROUTINES **********************/
116 qdio_get_micros(void)
118 return (get_clock() >> 12); /* time>>12 is microseconds */
122 * unfortunately, we can't just xchg the values; in do_QDIO we want to reserve
123 * the q in any case, so that we'll not be interrupted when we are in
124 * qdio_mark_tiq... shouldn't have a really bad impact, as reserving almost
125 * ever works (last famous words)
128 qdio_reserve_q(struct qdio_q *q)
130 return atomic_add_return(1,&q->use_count) - 1;
134 qdio_release_q(struct qdio_q *q)
136 atomic_dec(&q->use_count);
141 qdio_check_ccq(struct qdio_q *q, unsigned int ccq)
145 if (ccq == 0 || ccq == 32 || ccq == 96)
149 /*notify devices immediately*/
150 sprintf(dbf_text,"%d", ccq);
151 QDIO_DBF_TEXT2(1,trace,dbf_text);
154 /* EQBS: extract buffer states */
156 qdio_do_eqbs(struct qdio_q *q, unsigned char *state,
157 unsigned int *start, unsigned int *cnt)
159 struct qdio_irq *irq;
160 unsigned int tmp_cnt, q_no, ccq;
166 irq = (struct qdio_irq*)q->irq_ptr;
169 q_no += irq->no_input_qs;
171 ccq = do_eqbs(irq->sch_token, state, q_no, start, cnt);
172 rc = qdio_check_ccq(q, ccq);
174 QDIO_DBF_TEXT5(1,trace,"eqAGAIN");
178 QDIO_DBF_TEXT2(1,trace,"eqberr");
179 sprintf(dbf_text,"%2x,%2x,%d,%d",tmp_cnt, *cnt, ccq, q_no);
180 QDIO_DBF_TEXT2(1,trace,dbf_text);
181 q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION|
182 QDIO_STATUS_LOOK_FOR_ERROR,
183 0, 0, 0, -1, -1, q->int_parm);
186 return (tmp_cnt - *cnt);
189 /* SQBS: set buffer states */
191 qdio_do_sqbs(struct qdio_q *q, unsigned char state,
192 unsigned int *start, unsigned int *cnt)
194 struct qdio_irq *irq;
195 unsigned int tmp_cnt, q_no, ccq;
201 irq = (struct qdio_irq*)q->irq_ptr;
204 q_no += irq->no_input_qs;
206 ccq = do_sqbs(irq->sch_token, state, q_no, start, cnt);
207 rc = qdio_check_ccq(q, ccq);
209 QDIO_DBF_TEXT5(1,trace,"sqAGAIN");
213 QDIO_DBF_TEXT3(1,trace,"sqberr");
214 sprintf(dbf_text,"%2x,%2x,%d,%d",tmp_cnt,*cnt,ccq,q_no);
215 QDIO_DBF_TEXT3(1,trace,dbf_text);
216 q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION|
217 QDIO_STATUS_LOOK_FOR_ERROR,
218 0, 0, 0, -1, -1, q->int_parm);
221 return (tmp_cnt - *cnt);
225 qdio_set_slsb(struct qdio_q *q, unsigned int *bufno,
226 unsigned char state, unsigned int *count)
229 struct qdio_irq *irq;
231 irq = (struct qdio_irq*)q->irq_ptr;
232 if (!irq->is_qebsm) {
233 slsb = (char *)&q->slsb.acc.val[(*bufno)];
237 return qdio_do_sqbs(q, state, bufno, count);
240 #ifdef CONFIG_QDIO_DEBUG
242 qdio_trace_slsb(struct qdio_q *q)
244 if (q->queue_type==QDIO_TRACE_QTYPE) {
246 QDIO_DBF_HEX2(0,slsb_in,&q->slsb,
247 QDIO_MAX_BUFFERS_PER_Q);
249 QDIO_DBF_HEX2(0,slsb_out,&q->slsb,
250 QDIO_MAX_BUFFERS_PER_Q);
256 set_slsb(struct qdio_q *q, unsigned int *bufno,
257 unsigned char state, unsigned int *count)
260 #ifdef CONFIG_QDIO_DEBUG
263 rc = qdio_set_slsb(q, bufno, state, count);
264 #ifdef CONFIG_QDIO_DEBUG
270 qdio_siga_sync(struct qdio_q *q, unsigned int gpr2,
275 QDIO_DBF_TEXT4(0,trace,"sigasync");
276 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
278 if (qdio_performance_stats)
279 perf_stats.siga_syncs++;
281 cc = do_siga_sync(q->schid, gpr2, gpr3);
283 QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*));
289 qdio_siga_sync_q(struct qdio_q *q)
292 return qdio_siga_sync(q, 0, q->mask);
293 return qdio_siga_sync(q, q->mask, 0);
297 __do_siga_output(struct qdio_q *q, unsigned int *busy_bit)
299 struct qdio_irq *irq;
303 irq = (struct qdio_irq *) q->irq_ptr;
305 schid = *((u32 *)&q->schid);
307 schid = irq->sch_token;
310 return do_siga_output(schid, q->mask, busy_bit, fc);
314 * returns QDIO_SIGA_ERROR_ACCESS_EXCEPTION as cc, when SIGA returns
315 * an access exception
318 qdio_siga_output(struct qdio_q *q)
324 if (qdio_performance_stats)
325 perf_stats.siga_outs++;
327 QDIO_DBF_TEXT4(0,trace,"sigaout");
328 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
331 cc = __do_siga_output(q, &busy_bit);
332 //QDIO_PRINT_ERR("cc=%x, busy=%x\n",cc,busy_bit);
333 if ((cc==2) && (busy_bit) && (q->is_iqdio_q)) {
336 if ((NOW-start_time)>QDIO_BUSY_BIT_PATIENCE)
342 if ((cc==2) && (busy_bit))
343 cc |= QDIO_SIGA_ERROR_B_BIT_SET;
346 QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*));
352 qdio_siga_input(struct qdio_q *q)
356 QDIO_DBF_TEXT4(0,trace,"sigain");
357 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
359 if (qdio_performance_stats)
360 perf_stats.siga_ins++;
362 cc = do_siga_input(q->schid, q->mask);
365 QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*));
370 /* locked by the locks in qdio_activate and qdio_cleanup */
372 qdio_get_indicator(void)
376 for (i=1;i<INDICATORS_PER_CACHELINE;i++)
377 if (!indicator_used[i]) {
381 atomic_inc(&spare_indicator_usecount);
382 return (__u32 * volatile) &spare_indicator;
385 /* locked by the locks in qdio_activate and qdio_cleanup */
387 qdio_put_indicator(__u32 *addr)
391 if ( (addr) && (addr!=&spare_indicator) ) {
395 if (addr == &spare_indicator)
396 atomic_dec(&spare_indicator_usecount);
400 tiqdio_clear_summary_bit(__u32 *location)
402 QDIO_DBF_TEXT5(0,trace,"clrsummb");
403 QDIO_DBF_HEX5(0,trace,&location,sizeof(void*));
409 tiqdio_set_summary_bit(__u32 *location)
411 QDIO_DBF_TEXT5(0,trace,"setsummb");
412 QDIO_DBF_HEX5(0,trace,&location,sizeof(void*));
418 tiqdio_sched_tl(void)
420 tasklet_hi_schedule(&tiqdio_tasklet);
424 qdio_mark_tiq(struct qdio_q *q)
428 QDIO_DBF_TEXT4(0,trace,"mark iq");
429 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
431 spin_lock_irqsave(&ttiq_list_lock,flags);
432 if (unlikely(atomic_read(&q->is_in_shutdown)))
438 if ((q->list_prev) || (q->list_next))
446 q->list_next=tiq_list;
447 q->list_prev=tiq_list->list_prev;
448 tiq_list->list_prev->list_next=q;
449 tiq_list->list_prev=q;
451 spin_unlock_irqrestore(&ttiq_list_lock,flags);
453 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
457 spin_unlock_irqrestore(&ttiq_list_lock,flags);
462 qdio_mark_q(struct qdio_q *q)
464 QDIO_DBF_TEXT4(0,trace,"mark q");
465 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
467 if (unlikely(atomic_read(&q->is_in_shutdown)))
470 tasklet_schedule(&q->tasklet);
474 qdio_stop_polling(struct qdio_q *q)
476 #ifdef QDIO_USE_PROCESSING_STATE
477 unsigned int tmp, gsf, count = 1;
478 unsigned char state = 0;
479 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
481 if (!atomic_xchg(&q->polling,0))
484 QDIO_DBF_TEXT4(0,trace,"stoppoll");
485 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
487 /* show the card that we are not polling anymore */
491 tmp = gsf = GET_SAVED_FRONTIER(q);
492 tmp = ((tmp + QDIO_MAX_BUFFERS_PER_Q-1) & (QDIO_MAX_BUFFERS_PER_Q-1) );
493 set_slsb(q, &tmp, SLSB_P_INPUT_NOT_INIT, &count);
496 * we don't issue this SYNC_MEMORY, as we trust Rick T and
497 * moreover will not use the PROCESSING state under VM, so
498 * q->polling was 0 anyway
503 qdio_do_eqbs(q, &state, &gsf, &count);
505 state = q->slsb.acc.val[gsf];
506 if (state != SLSB_P_INPUT_PRIMED)
509 * set our summary bit again, as otherwise there is a
510 * small window we can miss between resetting it and
511 * checking for PRIMED state
514 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
517 #else /* QDIO_USE_PROCESSING_STATE */
519 #endif /* QDIO_USE_PROCESSING_STATE */
523 * see the comment in do_QDIO and before qdio_reserve_q about the
524 * sophisticated locking outside of unmark_q, so that we don't need to
525 * disable the interrupts :-)
528 qdio_unmark_q(struct qdio_q *q)
532 QDIO_DBF_TEXT4(0,trace,"unmark q");
533 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
535 if ((!q->list_prev)||(!q->list_next))
538 if ((q->is_thinint_q)&&(q->is_input_q)) {
540 spin_lock_irqsave(&ttiq_list_lock,flags);
541 /* in case cleanup has done this already and simultanously
542 * qdio_unmark_q is called from the interrupt handler, we've
543 * got to check this in this specific case again */
544 if ((!q->list_prev)||(!q->list_next))
546 if (q->list_next==q) {
547 /* q was the only interesting q */
552 q->list_next->list_prev=q->list_prev;
553 q->list_prev->list_next=q->list_next;
554 tiq_list=q->list_next;
559 spin_unlock_irqrestore(&ttiq_list_lock,flags);
563 static inline unsigned long
564 tiqdio_clear_global_summary(void)
568 QDIO_DBF_TEXT5(0,trace,"clrglobl");
570 time = do_clear_global_summary();
572 QDIO_DBF_HEX5(0,trace,&time,sizeof(unsigned long));
578 /************************* OUTBOUND ROUTINES *******************************/
580 qdio_qebsm_get_outbound_buffer_frontier(struct qdio_q *q)
582 struct qdio_irq *irq;
584 unsigned int cnt, count, ftc;
586 irq = (struct qdio_irq *) q->irq_ptr;
587 if ((!q->is_iqdio_q) && (!q->hydra_gives_outbound_pcis))
590 ftc = q->first_to_check;
591 count = qdio_min(atomic_read(&q->number_of_buffers_used),
592 (QDIO_MAX_BUFFERS_PER_Q-1));
594 return q->first_to_check;
595 cnt = qdio_do_eqbs(q, &state, &ftc, &count);
597 return q->first_to_check;
599 case SLSB_P_OUTPUT_ERROR:
600 QDIO_DBF_TEXT3(0,trace,"outperr");
601 atomic_sub(cnt , &q->number_of_buffers_used);
603 q->error_status_flags |=
604 QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR;
605 q->qdio_error = SLSB_P_OUTPUT_ERROR;
606 q->error_status_flags |= QDIO_STATUS_LOOK_FOR_ERROR;
607 q->first_to_check = ftc;
609 case SLSB_P_OUTPUT_EMPTY:
610 QDIO_DBF_TEXT5(0,trace,"outpempt");
611 atomic_sub(cnt, &q->number_of_buffers_used);
612 q->first_to_check = ftc;
614 case SLSB_CU_OUTPUT_PRIMED:
615 /* all buffers primed */
616 QDIO_DBF_TEXT5(0,trace,"outpprim");
621 QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int));
622 return q->first_to_check;
626 qdio_qebsm_get_inbound_buffer_frontier(struct qdio_q *q)
628 struct qdio_irq *irq;
630 int tmp, ftc, count, cnt;
634 irq = (struct qdio_irq *) q->irq_ptr;
635 ftc = q->first_to_check;
636 count = qdio_min(atomic_read(&q->number_of_buffers_used),
637 (QDIO_MAX_BUFFERS_PER_Q-1));
639 return q->first_to_check;
640 cnt = qdio_do_eqbs(q, &state, &ftc, &count);
642 return q->first_to_check;
644 case SLSB_P_INPUT_ERROR :
645 #ifdef CONFIG_QDIO_DEBUG
646 QDIO_DBF_TEXT3(1,trace,"inperr");
647 sprintf(dbf_text,"%2x,%2x",ftc,count);
648 QDIO_DBF_TEXT3(1,trace,dbf_text);
649 #endif /* CONFIG_QDIO_DEBUG */
651 q->error_status_flags |=
652 QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR;
653 q->qdio_error = SLSB_P_INPUT_ERROR;
654 q->error_status_flags |= QDIO_STATUS_LOOK_FOR_ERROR;
655 atomic_sub(cnt, &q->number_of_buffers_used);
656 q->first_to_check = ftc;
658 case SLSB_P_INPUT_PRIMED :
659 QDIO_DBF_TEXT3(0,trace,"inptprim");
660 sprintf(dbf_text,"%2x,%2x",ftc,count);
661 QDIO_DBF_TEXT3(1,trace,dbf_text);
663 ftc = q->first_to_check;
664 #ifdef QDIO_USE_PROCESSING_STATE
667 tmp = set_slsb(q, &ftc, SLSB_P_INPUT_NOT_INIT, &cnt);
672 tmp += set_slsb(q, &ftc,
673 SLSB_P_INPUT_PROCESSING, &cnt);
674 atomic_set(&q->polling, 1);
676 tmp = set_slsb(q, &ftc, SLSB_P_INPUT_NOT_INIT, &cnt);
678 atomic_sub(tmp, &q->number_of_buffers_used);
679 q->first_to_check = ftc;
681 case SLSB_CU_INPUT_EMPTY:
682 case SLSB_P_INPUT_NOT_INIT:
683 case SLSB_P_INPUT_PROCESSING:
684 QDIO_DBF_TEXT5(0,trace,"inpnipro");
689 QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int));
690 return q->first_to_check;
694 qdio_get_outbound_buffer_frontier(struct qdio_q *q)
696 struct qdio_irq *irq;
698 unsigned int count = 1;
699 int first_not_to_check, f, f_mod_no;
702 QDIO_DBF_TEXT4(0,trace,"getobfro");
703 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
705 irq = (struct qdio_irq *) q->irq_ptr;
707 return qdio_qebsm_get_outbound_buffer_frontier(q);
709 slsb=&q->slsb.acc.val[0];
710 f_mod_no=f=q->first_to_check;
712 * f points to already processed elements, so f+no_used is correct...
713 * ... but: we don't check 128 buffers, as otherwise
714 * qdio_has_outbound_q_moved would return 0
716 first_not_to_check=f+qdio_min(atomic_read(&q->number_of_buffers_used),
717 (QDIO_MAX_BUFFERS_PER_Q-1));
719 if ((!q->is_iqdio_q)&&(!q->hydra_gives_outbound_pcis))
723 if (f==first_not_to_check)
726 switch(slsb[f_mod_no]) {
728 /* the adapter has not fetched the output yet */
729 case SLSB_CU_OUTPUT_PRIMED:
730 QDIO_DBF_TEXT5(0,trace,"outpprim");
733 /* the adapter got it */
734 case SLSB_P_OUTPUT_EMPTY:
735 atomic_dec(&q->number_of_buffers_used);
737 f_mod_no=f&(QDIO_MAX_BUFFERS_PER_Q-1);
738 QDIO_DBF_TEXT5(0,trace,"outpempt");
741 case SLSB_P_OUTPUT_ERROR:
742 QDIO_DBF_TEXT3(0,trace,"outperr");
743 sprintf(dbf_text,"%x-%x-%x",f_mod_no,
744 q->sbal[f_mod_no]->element[14].sbalf.value,
745 q->sbal[f_mod_no]->element[15].sbalf.value);
746 QDIO_DBF_TEXT3(1,trace,dbf_text);
747 QDIO_DBF_HEX2(1,sbal,q->sbal[f_mod_no],256);
749 /* kind of process the buffer */
750 set_slsb(q, &f_mod_no, SLSB_P_OUTPUT_NOT_INIT, &count);
753 * we increment the frontier, as this buffer
754 * was processed obviously
756 atomic_dec(&q->number_of_buffers_used);
757 f_mod_no=(f_mod_no+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
760 q->error_status_flags|=
761 QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR;
762 q->qdio_error=SLSB_P_OUTPUT_ERROR;
763 q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR;
769 QDIO_DBF_TEXT5(0,trace,"outpni");
772 return (q->first_to_check=f_mod_no);
775 /* all buffers are processed */
777 qdio_is_outbound_q_done(struct qdio_q *q)
780 #ifdef CONFIG_QDIO_DEBUG
784 no_used=atomic_read(&q->number_of_buffers_used);
786 #ifdef CONFIG_QDIO_DEBUG
788 sprintf(dbf_text,"oqisnt%02x",no_used);
789 QDIO_DBF_TEXT4(0,trace,dbf_text);
791 QDIO_DBF_TEXT4(0,trace,"oqisdone");
793 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
794 #endif /* CONFIG_QDIO_DEBUG */
799 qdio_has_outbound_q_moved(struct qdio_q *q)
803 i=qdio_get_outbound_buffer_frontier(q);
805 if ( (i!=GET_SAVED_FRONTIER(q)) ||
806 (q->error_status_flags&QDIO_STATUS_LOOK_FOR_ERROR) ) {
808 QDIO_DBF_TEXT4(0,trace,"oqhasmvd");
809 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
812 QDIO_DBF_TEXT4(0,trace,"oqhsntmv");
813 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
819 qdio_kick_outbound_q(struct qdio_q *q)
822 #ifdef CONFIG_QDIO_DEBUG
825 QDIO_DBF_TEXT4(0,trace,"kickoutq");
826 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
827 #endif /* CONFIG_QDIO_DEBUG */
832 /* here's the story with cc=2 and busy bit set (thanks, Rick):
833 * VM's CP could present us cc=2 and busy bit set on SIGA-write
834 * during reconfiguration of their Guest LAN (only in HIPERS mode,
835 * QDIO mode is asynchronous -- cc=2 and busy bit there will take
836 * the queues down immediately; and not being under VM we have a
837 * problem on cc=2 and busy bit set right away).
839 * Therefore qdio_siga_output will try for a short time constantly,
840 * if such a condition occurs. If it doesn't change, it will
841 * increase the busy_siga_counter and save the timestamp, and
842 * schedule the queue for later processing (via mark_q, using the
843 * queue tasklet). __qdio_outbound_processing will check out the
844 * counter. If non-zero, it will call qdio_kick_outbound_q as often
845 * as the value of the counter. This will attempt further SIGA
846 * instructions. For each successful SIGA, the counter is
847 * decreased, for failing SIGAs the counter remains the same, after
849 * After some time of no movement, qdio_kick_outbound_q will
850 * finally fail and reflect corresponding error codes to call
851 * the upper layer module and have it take the queues down.
853 * Note that this is a change from the original HiperSockets design
854 * (saying cc=2 and busy bit means take the queues down), but in
855 * these days Guest LAN didn't exist... excessive cc=2 with busy bit
856 * conditions will still take the queues down, but the threshold is
857 * higher due to the Guest LAN environment.
861 result=qdio_siga_output(q);
865 /* went smooth this time, reset timestamp */
866 #ifdef CONFIG_QDIO_DEBUG
867 QDIO_DBF_TEXT3(0,trace,"cc2reslv");
868 sprintf(dbf_text,"%4x%2x%2x",q->schid.sch_no,q->q_no,
869 atomic_read(&q->busy_siga_counter));
870 QDIO_DBF_TEXT3(0,trace,dbf_text);
871 #endif /* CONFIG_QDIO_DEBUG */
872 q->timing.busy_start=0;
874 case (2|QDIO_SIGA_ERROR_B_BIT_SET):
875 /* cc=2 and busy bit: */
876 atomic_inc(&q->busy_siga_counter);
878 /* if the last siga was successful, save
880 if (!q->timing.busy_start)
881 q->timing.busy_start=NOW;
883 /* if we're in time, don't touch error_status_flags
885 if (NOW-q->timing.busy_start<QDIO_BUSY_BIT_GIVE_UP) {
889 QDIO_DBF_TEXT2(0,trace,"cc2REPRT");
890 #ifdef CONFIG_QDIO_DEBUG
891 sprintf(dbf_text,"%4x%2x%2x",q->schid.sch_no,q->q_no,
892 atomic_read(&q->busy_siga_counter));
893 QDIO_DBF_TEXT3(0,trace,dbf_text);
894 #endif /* CONFIG_QDIO_DEBUG */
895 /* else fallthrough and report error */
897 /* for plain cc=1, 2 or 3: */
899 q->error_status_flags|=
900 QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR;
901 q->error_status_flags|=
902 QDIO_STATUS_LOOK_FOR_ERROR;
903 q->siga_error=result;
908 qdio_kick_outbound_handler(struct qdio_q *q)
910 int start, end, real_end, count;
911 #ifdef CONFIG_QDIO_DEBUG
915 start = q->first_element_to_kick;
916 /* last_move_ftc was just updated */
917 real_end = GET_SAVED_FRONTIER(q);
918 end = (real_end+QDIO_MAX_BUFFERS_PER_Q-1)&
919 (QDIO_MAX_BUFFERS_PER_Q-1);
920 count = (end+QDIO_MAX_BUFFERS_PER_Q+1-start)&
921 (QDIO_MAX_BUFFERS_PER_Q-1);
923 #ifdef CONFIG_QDIO_DEBUG
924 QDIO_DBF_TEXT4(0,trace,"kickouth");
925 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
927 sprintf(dbf_text,"s=%2xc=%2x",start,count);
928 QDIO_DBF_TEXT4(0,trace,dbf_text);
929 #endif /* CONFIG_QDIO_DEBUG */
931 if (q->state==QDIO_IRQ_STATE_ACTIVE)
932 q->handler(q->cdev,QDIO_STATUS_OUTBOUND_INT|
933 q->error_status_flags,
934 q->qdio_error,q->siga_error,q->q_no,start,count,
937 /* for the next time: */
938 q->first_element_to_kick=real_end;
941 q->error_status_flags=0;
945 __qdio_outbound_processing(struct qdio_q *q)
949 QDIO_DBF_TEXT4(0,trace,"qoutproc");
950 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
952 if (unlikely(qdio_reserve_q(q))) {
954 if (qdio_performance_stats)
956 /* as we're sissies, we'll check next time */
957 if (likely(!atomic_read(&q->is_in_shutdown))) {
959 QDIO_DBF_TEXT4(0,trace,"busy,agn");
963 if (qdio_performance_stats) {
965 perf_stats.tl_runs++;
968 /* see comment in qdio_kick_outbound_q */
969 siga_attempts=atomic_read(&q->busy_siga_counter);
970 while (siga_attempts) {
971 atomic_dec(&q->busy_siga_counter);
972 qdio_kick_outbound_q(q);
976 if (qdio_has_outbound_q_moved(q))
977 qdio_kick_outbound_handler(q);
981 * for asynchronous queues, we better check, if the sent
982 * buffer is already switched from PRIMED to EMPTY.
984 if ((q->queue_type == QDIO_IQDIO_QFMT_ASYNCH) &&
985 !qdio_is_outbound_q_done(q))
988 } else if (!q->hydra_gives_outbound_pcis)
989 if (!qdio_is_outbound_q_done(q))
996 qdio_outbound_processing(struct qdio_q *q)
998 __qdio_outbound_processing(q);
1001 /************************* INBOUND ROUTINES *******************************/
1005 qdio_get_inbound_buffer_frontier(struct qdio_q *q)
1007 struct qdio_irq *irq;
1009 volatile char *slsb;
1010 unsigned int count = 1;
1011 int first_not_to_check;
1012 #ifdef CONFIG_QDIO_DEBUG
1014 #endif /* CONFIG_QDIO_DEBUG */
1015 #ifdef QDIO_USE_PROCESSING_STATE
1016 int last_position=-1;
1017 #endif /* QDIO_USE_PROCESSING_STATE */
1019 QDIO_DBF_TEXT4(0,trace,"getibfro");
1020 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1022 irq = (struct qdio_irq *) q->irq_ptr;
1024 return qdio_qebsm_get_inbound_buffer_frontier(q);
1026 slsb=&q->slsb.acc.val[0];
1027 f_mod_no=f=q->first_to_check;
1029 * we don't check 128 buffers, as otherwise qdio_has_inbound_q_moved
1032 first_not_to_check=f+qdio_min(atomic_read(&q->number_of_buffers_used),
1033 (QDIO_MAX_BUFFERS_PER_Q-1));
1036 * we don't use this one, as a PCI or we after a thin interrupt
1037 * will sync the queues
1042 f_mod_no=f&(QDIO_MAX_BUFFERS_PER_Q-1);
1043 if (f==first_not_to_check)
1045 switch (slsb[f_mod_no]) {
1047 /* CU_EMPTY means frontier is reached */
1048 case SLSB_CU_INPUT_EMPTY:
1049 QDIO_DBF_TEXT5(0,trace,"inptempt");
1052 /* P_PRIMED means set slsb to P_PROCESSING and move on */
1053 case SLSB_P_INPUT_PRIMED:
1054 QDIO_DBF_TEXT5(0,trace,"inptprim");
1056 #ifdef QDIO_USE_PROCESSING_STATE
1058 * as soon as running under VM, polling the input queues will
1059 * kill VM in terms of CP overhead
1062 set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count);
1064 /* set the previous buffer to NOT_INIT. The current
1065 * buffer will be set to PROCESSING at the end of
1066 * this function to avoid further interrupts. */
1067 if (last_position>=0)
1068 set_slsb(q, &last_position,
1069 SLSB_P_INPUT_NOT_INIT, &count);
1070 atomic_set(&q->polling,1);
1071 last_position=f_mod_no;
1073 #else /* QDIO_USE_PROCESSING_STATE */
1074 set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count);
1075 #endif /* QDIO_USE_PROCESSING_STATE */
1077 * not needed, as the inbound queue will be synced on the next
1078 * siga-r, resp. tiqdio_is_inbound_q_done will do the siga-s
1082 atomic_dec(&q->number_of_buffers_used);
1085 case SLSB_P_INPUT_NOT_INIT:
1086 case SLSB_P_INPUT_PROCESSING:
1087 QDIO_DBF_TEXT5(0,trace,"inpnipro");
1090 /* P_ERROR means frontier is reached, break and report error */
1091 case SLSB_P_INPUT_ERROR:
1092 #ifdef CONFIG_QDIO_DEBUG
1093 sprintf(dbf_text,"inperr%2x",f_mod_no);
1094 QDIO_DBF_TEXT3(1,trace,dbf_text);
1095 #endif /* CONFIG_QDIO_DEBUG */
1096 QDIO_DBF_HEX2(1,sbal,q->sbal[f_mod_no],256);
1098 /* kind of process the buffer */
1099 set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count);
1102 q->error_status_flags|=
1103 QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR;
1104 q->qdio_error=SLSB_P_INPUT_ERROR;
1105 q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR;
1107 /* we increment the frontier, as this buffer
1108 * was processed obviously */
1109 f_mod_no=(f_mod_no+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
1110 atomic_dec(&q->number_of_buffers_used);
1112 #ifdef QDIO_USE_PROCESSING_STATE
1114 #endif /* QDIO_USE_PROCESSING_STATE */
1118 /* everything else means frontier not changed (HALTED or so) */
1123 q->first_to_check=f_mod_no;
1125 #ifdef QDIO_USE_PROCESSING_STATE
1126 if (last_position>=0)
1127 set_slsb(q, &last_position, SLSB_P_INPUT_PROCESSING, &count);
1128 #endif /* QDIO_USE_PROCESSING_STATE */
1130 QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int));
1132 return q->first_to_check;
1136 qdio_has_inbound_q_moved(struct qdio_q *q)
1140 static int old_pcis=0;
1141 static int old_thinints=0;
1143 if (qdio_performance_stats) {
1144 if ((old_pcis==perf_stats.pcis)&&
1145 (old_thinints==perf_stats.thinints))
1146 perf_stats.start_time_inbound=NOW;
1148 old_pcis=perf_stats.pcis;
1151 i=qdio_get_inbound_buffer_frontier(q);
1152 if ( (i!=GET_SAVED_FRONTIER(q)) ||
1153 (q->error_status_flags&QDIO_STATUS_LOOK_FOR_ERROR) ) {
1155 if ((!q->siga_sync)&&(!q->hydra_gives_outbound_pcis))
1158 QDIO_DBF_TEXT4(0,trace,"inhasmvd");
1159 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1162 QDIO_DBF_TEXT4(0,trace,"inhsntmv");
1163 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1168 /* means, no more buffers to be filled */
1170 tiqdio_is_inbound_q_done(struct qdio_q *q)
1173 unsigned int start_buf, count;
1174 unsigned char state = 0;
1175 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
1177 #ifdef CONFIG_QDIO_DEBUG
1181 no_used=atomic_read(&q->number_of_buffers_used);
1183 /* propagate the change from 82 to 80 through VM */
1186 #ifdef CONFIG_QDIO_DEBUG
1188 sprintf(dbf_text,"iqisnt%02x",no_used);
1189 QDIO_DBF_TEXT4(0,trace,dbf_text);
1191 QDIO_DBF_TEXT4(0,trace,"iniqisdo");
1193 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1194 #endif /* CONFIG_QDIO_DEBUG */
1198 if (!q->siga_sync && !irq->is_qebsm)
1199 /* we'll check for more primed buffers in qeth_stop_polling */
1201 if (irq->is_qebsm) {
1203 start_buf = q->first_to_check;
1204 qdio_do_eqbs(q, &state, &start_buf, &count);
1206 state = q->slsb.acc.val[q->first_to_check];
1207 if (state != SLSB_P_INPUT_PRIMED)
1209 * nothing more to do, if next buffer is not PRIMED.
1210 * note that we did a SYNC_MEMORY before, that there
1211 * has been a sychnronization.
1212 * we will return 0 below, as there is nothing to do
1213 * (stop_polling not necessary, as we have not been
1214 * using the PROCESSING state
1219 * ok, the next input buffer is primed. that means, that device state
1220 * change indicator and adapter local summary are set, so we will find
1222 * we will return 0 below, as there is nothing to do, except scheduling
1223 * ourselves for the next time.
1225 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1231 qdio_is_inbound_q_done(struct qdio_q *q)
1234 unsigned int start_buf, count;
1235 unsigned char state = 0;
1236 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
1238 #ifdef CONFIG_QDIO_DEBUG
1242 no_used=atomic_read(&q->number_of_buffers_used);
1245 * we need that one for synchronization with the adapter, as it
1246 * does a kind of PCI avoidance
1251 QDIO_DBF_TEXT4(0,trace,"inqisdnA");
1252 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1253 QDIO_DBF_TEXT4(0,trace,dbf_text);
1256 if (irq->is_qebsm) {
1258 start_buf = q->first_to_check;
1259 qdio_do_eqbs(q, &state, &start_buf, &count);
1261 state = q->slsb.acc.val[q->first_to_check];
1262 if (state == SLSB_P_INPUT_PRIMED) {
1263 /* we got something to do */
1264 QDIO_DBF_TEXT4(0,trace,"inqisntA");
1265 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1269 /* on VM, we don't poll, so the q is always done here */
1272 if (q->hydra_gives_outbound_pcis)
1276 * at this point we know, that inbound first_to_check
1277 * has (probably) not moved (see qdio_inbound_processing)
1279 if (NOW>GET_SAVED_TIMESTAMP(q)+q->timing.threshold) {
1280 #ifdef CONFIG_QDIO_DEBUG
1281 QDIO_DBF_TEXT4(0,trace,"inqisdon");
1282 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1283 sprintf(dbf_text,"pf%02xcn%02x",q->first_to_check,no_used);
1284 QDIO_DBF_TEXT4(0,trace,dbf_text);
1285 #endif /* CONFIG_QDIO_DEBUG */
1288 #ifdef CONFIG_QDIO_DEBUG
1289 QDIO_DBF_TEXT4(0,trace,"inqisntd");
1290 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1291 sprintf(dbf_text,"pf%02xcn%02x",q->first_to_check,no_used);
1292 QDIO_DBF_TEXT4(0,trace,dbf_text);
1293 #endif /* CONFIG_QDIO_DEBUG */
1299 qdio_kick_inbound_handler(struct qdio_q *q)
1301 int count, start, end, real_end, i;
1302 #ifdef CONFIG_QDIO_DEBUG
1306 QDIO_DBF_TEXT4(0,trace,"kickinh");
1307 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1309 start=q->first_element_to_kick;
1310 real_end=q->first_to_check;
1311 end=(real_end+QDIO_MAX_BUFFERS_PER_Q-1)&(QDIO_MAX_BUFFERS_PER_Q-1);
1319 i=(i+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
1322 #ifdef CONFIG_QDIO_DEBUG
1323 sprintf(dbf_text,"s=%2xc=%2x",start,count);
1324 QDIO_DBF_TEXT4(0,trace,dbf_text);
1325 #endif /* CONFIG_QDIO_DEBUG */
1327 if (likely(q->state==QDIO_IRQ_STATE_ACTIVE))
1329 QDIO_STATUS_INBOUND_INT|q->error_status_flags,
1330 q->qdio_error,q->siga_error,q->q_no,start,count,
1333 /* for the next time: */
1334 q->first_element_to_kick=real_end;
1337 q->error_status_flags=0;
1339 if (qdio_performance_stats) {
1340 perf_stats.inbound_time+=NOW-perf_stats.start_time_inbound;
1341 perf_stats.inbound_cnt++;
1346 __tiqdio_inbound_processing(struct qdio_q *q, int spare_ind_was_set)
1348 struct qdio_irq *irq_ptr;
1352 QDIO_DBF_TEXT4(0,trace,"iqinproc");
1353 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1356 * we first want to reserve the q, so that we know, that we don't
1357 * interrupt ourselves and call qdio_unmark_q, as is_in_shutdown might
1360 if (unlikely(qdio_reserve_q(q))) {
1362 if (qdio_performance_stats)
1365 * as we might just be about to stop polling, we make
1366 * sure that we check again at least once more
1371 if (qdio_performance_stats)
1373 if (unlikely(atomic_read(&q->is_in_shutdown))) {
1379 * we reset spare_ind_was_set, when the queue does not use the
1382 if (spare_ind_was_set)
1383 spare_ind_was_set = (q->dev_st_chg_ind == &spare_indicator);
1385 if (!(*(q->dev_st_chg_ind)) && !spare_ind_was_set)
1388 * q->dev_st_chg_ind is the indicator, be it shared or not.
1389 * only clear it, if indicator is non-shared
1391 if (!spare_ind_was_set)
1392 tiqdio_clear_summary_bit((__u32*)q->dev_st_chg_ind);
1394 if (q->hydra_gives_outbound_pcis) {
1395 if (!q->siga_sync_done_on_thinints) {
1397 } else if ((!q->siga_sync_done_on_outb_tis)&&
1398 (q->hydra_gives_outbound_pcis)) {
1399 SYNC_MEMORY_ALL_OUTB;
1405 * maybe we have to do work on our outbound queues... at least
1406 * we have to check the outbound-int-capable thinint-capable
1409 if (q->hydra_gives_outbound_pcis) {
1410 irq_ptr = (struct qdio_irq*)q->irq_ptr;
1411 for (i=0;i<irq_ptr->no_output_qs;i++) {
1412 oq = irq_ptr->output_qs[i];
1413 if (!qdio_is_outbound_q_done(oq)) {
1414 if (qdio_performance_stats)
1415 perf_stats.tl_runs--;
1416 __qdio_outbound_processing(oq);
1421 if (!qdio_has_inbound_q_moved(q))
1424 qdio_kick_inbound_handler(q);
1425 if (tiqdio_is_inbound_q_done(q))
1426 if (!qdio_stop_polling(q)) {
1428 * we set the flags to get into the stuff next time,
1429 * see also comment in qdio_stop_polling
1431 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1439 tiqdio_inbound_processing(struct qdio_q *q)
1441 __tiqdio_inbound_processing(q, atomic_read(&spare_indicator_usecount));
1445 __qdio_inbound_processing(struct qdio_q *q)
1449 QDIO_DBF_TEXT4(0,trace,"qinproc");
1450 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1452 if (unlikely(qdio_reserve_q(q))) {
1454 if (qdio_performance_stats)
1456 /* as we're sissies, we'll check next time */
1457 if (likely(!atomic_read(&q->is_in_shutdown))) {
1459 QDIO_DBF_TEXT4(0,trace,"busy,agn");
1463 if (qdio_performance_stats) {
1465 perf_stats.tl_runs++;
1469 if (qdio_has_inbound_q_moved(q)) {
1470 qdio_kick_inbound_handler(q);
1471 if (!qdio_stop_polling(q)) {
1473 if (q_laps<QDIO_Q_LAPS)
1478 if (!qdio_is_inbound_q_done(q))
1479 /* means poll time is not yet over */
1487 qdio_inbound_processing(struct qdio_q *q)
1489 __qdio_inbound_processing(q);
1492 /************************* MAIN ROUTINES *******************************/
1494 #ifdef QDIO_USE_PROCESSING_STATE
1496 tiqdio_reset_processing_state(struct qdio_q *q, int q_laps)
1504 * under VM, we have not used the PROCESSING state, so no
1505 * need to stop polling
1510 if (unlikely(qdio_reserve_q(q))) {
1512 if (qdio_performance_stats)
1515 * as we might just be about to stop polling, we make
1516 * sure that we check again at least once more
1520 * sanity -- we'd get here without setting the
1523 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1527 if (qdio_stop_polling(q)) {
1531 if (q_laps<QDIO_Q_LAPS-1) {
1536 * we set the flags to get into the stuff
1537 * next time, see also comment in qdio_stop_polling
1539 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1545 #endif /* QDIO_USE_PROCESSING_STATE */
1548 tiqdio_inbound_checks(void)
1551 int spare_ind_was_set=0;
1552 #ifdef QDIO_USE_PROCESSING_STATE
1554 #endif /* QDIO_USE_PROCESSING_STATE */
1556 QDIO_DBF_TEXT4(0,trace,"iqdinbck");
1557 QDIO_DBF_TEXT5(0,trace,"iqlocsum");
1559 #ifdef QDIO_USE_PROCESSING_STATE
1561 #endif /* QDIO_USE_PROCESSING_STATE */
1563 /* when the spare indicator is used and set, save that and clear it */
1564 if ((atomic_read(&spare_indicator_usecount)) && spare_indicator) {
1565 spare_ind_was_set = 1;
1566 tiqdio_clear_summary_bit((__u32*)&spare_indicator);
1569 q=(struct qdio_q*)tiq_list;
1573 __tiqdio_inbound_processing(q, spare_ind_was_set);
1574 q=(struct qdio_q*)q->list_next;
1575 } while (q!=(struct qdio_q*)tiq_list);
1577 #ifdef QDIO_USE_PROCESSING_STATE
1578 q=(struct qdio_q*)tiq_list;
1582 ret = tiqdio_reset_processing_state(q, q_laps);
1589 q = (struct qdio_q*)q->list_next;
1595 } while (q!=(struct qdio_q*)tiq_list);
1596 #endif /* QDIO_USE_PROCESSING_STATE */
1600 tiqdio_tl(unsigned long data)
1602 QDIO_DBF_TEXT4(0,trace,"iqdio_tl");
1604 if (qdio_performance_stats)
1605 perf_stats.tl_runs++;
1607 tiqdio_inbound_checks();
1610 /********************* GENERAL HELPER_ROUTINES ***********************/
1613 qdio_release_irq_memory(struct qdio_irq *irq_ptr)
1617 for (i=0;i<QDIO_MAX_QUEUES_PER_IRQ;i++) {
1618 if (!irq_ptr->input_qs[i])
1621 kfree(irq_ptr->input_qs[i]->slib);
1622 kfree(irq_ptr->input_qs[i]);
1625 if (!irq_ptr->output_qs[i])
1628 kfree(irq_ptr->output_qs[i]->slib);
1629 kfree(irq_ptr->output_qs[i]);
1632 kfree(irq_ptr->qdr);
1633 free_page((unsigned long) irq_ptr);
1637 qdio_set_impl_params(struct qdio_irq *irq_ptr,
1638 unsigned int qib_param_field_format,
1639 /* pointer to 128 bytes or NULL, if no param field */
1640 unsigned char *qib_param_field,
1641 /* pointer to no_queues*128 words of data or NULL */
1642 unsigned int no_input_qs,
1643 unsigned int no_output_qs,
1644 unsigned long *input_slib_elements,
1645 unsigned long *output_slib_elements)
1652 irq_ptr->qib.pfmt=qib_param_field_format;
1653 if (qib_param_field)
1654 memcpy(irq_ptr->qib.parm,qib_param_field,
1655 QDIO_MAX_BUFFERS_PER_Q);
1657 if (input_slib_elements)
1658 for (i=0;i<no_input_qs;i++) {
1659 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1660 irq_ptr->input_qs[i]->slib->slibe[j].parms=
1661 input_slib_elements[
1662 i*QDIO_MAX_BUFFERS_PER_Q+j];
1664 if (output_slib_elements)
1665 for (i=0;i<no_output_qs;i++) {
1666 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1667 irq_ptr->output_qs[i]->slib->slibe[j].parms=
1668 output_slib_elements[
1669 i*QDIO_MAX_BUFFERS_PER_Q+j];
1674 qdio_alloc_qs(struct qdio_irq *irq_ptr,
1675 int no_input_qs, int no_output_qs)
1681 for (i=0;i<no_input_qs;i++) {
1682 q = kzalloc(sizeof(struct qdio_q), GFP_KERNEL);
1685 QDIO_PRINT_ERR("kmalloc of q failed!\n");
1689 q->slib = kmalloc(PAGE_SIZE, GFP_KERNEL);
1691 QDIO_PRINT_ERR("kmalloc of slib failed!\n");
1695 irq_ptr->input_qs[i]=q;
1698 for (i=0;i<no_output_qs;i++) {
1699 q = kzalloc(sizeof(struct qdio_q), GFP_KERNEL);
1705 q->slib=kmalloc(PAGE_SIZE,GFP_KERNEL);
1707 QDIO_PRINT_ERR("kmalloc of slib failed!\n");
1711 irq_ptr->output_qs[i]=q;
1720 qdio_fill_qs(struct qdio_irq *irq_ptr, struct ccw_device *cdev,
1721 int no_input_qs, int no_output_qs,
1722 qdio_handler_t *input_handler,
1723 qdio_handler_t *output_handler,
1724 unsigned long int_parm,int q_format,
1725 unsigned long flags,
1726 void **inbound_sbals_array,
1727 void **outbound_sbals_array)
1731 char dbf_text[20]; /* see qdio_initialize */
1735 sprintf(dbf_text,"qfqs%4x",cdev->private->schid.sch_no);
1736 QDIO_DBF_TEXT0(0,setup,dbf_text);
1737 for (i=0;i<no_input_qs;i++) {
1738 q=irq_ptr->input_qs[i];
1740 memset(q,0,((char*)&q->slib)-((char*)q));
1741 sprintf(dbf_text,"in-q%4x",i);
1742 QDIO_DBF_TEXT0(0,setup,dbf_text);
1743 QDIO_DBF_HEX0(0,setup,&q,sizeof(void*));
1745 memset(q->slib,0,PAGE_SIZE);
1746 q->sl=(struct sl*)(((char*)q->slib)+PAGE_SIZE/2);
1750 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1751 q->sbal[j]=*(inbound_sbals_array++);
1753 q->queue_type=q_format;
1754 q->int_parm=int_parm;
1755 q->schid = irq_ptr->schid;
1756 q->irq_ptr = irq_ptr;
1761 q->first_to_check=0;
1763 q->handler=input_handler;
1764 q->dev_st_chg_ind=irq_ptr->dev_st_chg_ind;
1766 q->tasklet.data=(unsigned long)q;
1767 /* q->is_thinint_q isn't valid at this time, but
1768 * irq_ptr->is_thinint_irq is */
1769 q->tasklet.func=(void(*)(unsigned long))
1770 ((irq_ptr->is_thinint_irq)?&tiqdio_inbound_processing:
1771 &qdio_inbound_processing);
1773 /* actually this is not used for inbound queues. yet. */
1774 atomic_set(&q->busy_siga_counter,0);
1775 q->timing.busy_start=0;
1777 /* for (j=0;j<QDIO_STATS_NUMBER;j++)
1778 q->timing.last_transfer_times[j]=(qdio_get_micros()/
1779 QDIO_STATS_NUMBER)*j;
1780 q->timing.last_transfer_index=QDIO_STATS_NUMBER-1;
1784 if (i>0) irq_ptr->input_qs[i-1]->slib->nsliba=
1785 (unsigned long)(q->slib);
1786 q->slib->sla=(unsigned long)(q->sl);
1787 q->slib->slsba=(unsigned long)(&q->slsb.acc.val[0]);
1790 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1791 q->sl->element[j].sbal=(unsigned long)(q->sbal[j]);
1793 QDIO_DBF_TEXT2(0,setup,"sl-sb-b0");
1795 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1796 ptr=(void*)&q->slsb;
1797 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1798 ptr=(void*)q->sbal[0];
1799 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1802 if (!irq_ptr->is_qebsm) {
1803 unsigned int count = 1;
1804 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
1805 set_slsb(q, &j, SLSB_P_INPUT_NOT_INIT, &count);
1809 for (i=0;i<no_output_qs;i++) {
1810 q=irq_ptr->output_qs[i];
1811 memset(q,0,((char*)&q->slib)-((char*)q));
1813 sprintf(dbf_text,"outq%4x",i);
1814 QDIO_DBF_TEXT0(0,setup,dbf_text);
1815 QDIO_DBF_HEX0(0,setup,&q,sizeof(void*));
1817 memset(q->slib,0,PAGE_SIZE);
1818 q->sl=(struct sl*)(((char*)q->slib)+PAGE_SIZE/2);
1822 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1823 q->sbal[j]=*(outbound_sbals_array++);
1825 q->queue_type=q_format;
1826 if ((q->queue_type == QDIO_IQDIO_QFMT) &&
1827 (no_output_qs > 1) &&
1828 (i == no_output_qs-1))
1829 q->queue_type = QDIO_IQDIO_QFMT_ASYNCH;
1830 q->int_parm=int_parm;
1832 q->schid = irq_ptr->schid;
1834 q->irq_ptr = irq_ptr;
1837 q->first_to_check=0;
1839 q->handler=output_handler;
1841 q->tasklet.data=(unsigned long)q;
1842 q->tasklet.func=(void(*)(unsigned long))
1843 &qdio_outbound_processing;
1845 atomic_set(&q->busy_siga_counter,0);
1846 q->timing.busy_start=0;
1849 if (i>0) irq_ptr->output_qs[i-1]->slib->nsliba=
1850 (unsigned long)(q->slib);
1851 q->slib->sla=(unsigned long)(q->sl);
1852 q->slib->slsba=(unsigned long)(&q->slsb.acc.val[0]);
1855 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1856 q->sl->element[j].sbal=(unsigned long)(q->sbal[j]);
1858 QDIO_DBF_TEXT2(0,setup,"sl-sb-b0");
1860 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1861 ptr=(void*)&q->slsb;
1862 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1863 ptr=(void*)q->sbal[0];
1864 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1867 if (!irq_ptr->is_qebsm) {
1868 unsigned int count = 1;
1869 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
1870 set_slsb(q, &j, SLSB_P_OUTPUT_NOT_INIT, &count);
1876 qdio_fill_thresholds(struct qdio_irq *irq_ptr,
1877 unsigned int no_input_qs,
1878 unsigned int no_output_qs,
1879 unsigned int min_input_threshold,
1880 unsigned int max_input_threshold,
1881 unsigned int min_output_threshold,
1882 unsigned int max_output_threshold)
1887 for (i=0;i<no_input_qs;i++) {
1888 q=irq_ptr->input_qs[i];
1889 q->timing.threshold=max_input_threshold;
1890 /* for (j=0;j<QDIO_STATS_CLASSES;j++) {
1891 q->threshold_classes[j].threshold=
1892 min_input_threshold+
1893 (max_input_threshold-min_input_threshold)/
1896 qdio_use_thresholds(q,QDIO_STATS_CLASSES/2);*/
1898 for (i=0;i<no_output_qs;i++) {
1899 q=irq_ptr->output_qs[i];
1900 q->timing.threshold=max_output_threshold;
1901 /* for (j=0;j<QDIO_STATS_CLASSES;j++) {
1902 q->threshold_classes[j].threshold=
1903 min_output_threshold+
1904 (max_output_threshold-min_output_threshold)/
1907 qdio_use_thresholds(q,QDIO_STATS_CLASSES/2);*/
1912 tiqdio_thinint_handler(void)
1914 QDIO_DBF_TEXT4(0,trace,"thin_int");
1916 if (qdio_performance_stats) {
1917 perf_stats.thinints++;
1918 perf_stats.start_time_inbound=NOW;
1921 /* SVS only when needed:
1922 * issue SVS to benefit from iqdio interrupt avoidance
1923 * (SVS clears AISOI)*/
1925 tiqdio_clear_global_summary();
1927 tiqdio_inbound_checks();
1932 qdio_set_state(struct qdio_irq *irq_ptr, enum qdio_irq_states state)
1935 #ifdef CONFIG_QDIO_DEBUG
1938 QDIO_DBF_TEXT5(0,trace,"newstate");
1939 sprintf(dbf_text,"%4x%4x",irq_ptr->schid.sch_no,state);
1940 QDIO_DBF_TEXT5(0,trace,dbf_text);
1941 #endif /* CONFIG_QDIO_DEBUG */
1943 irq_ptr->state=state;
1944 for (i=0;i<irq_ptr->no_input_qs;i++)
1945 irq_ptr->input_qs[i]->state=state;
1946 for (i=0;i<irq_ptr->no_output_qs;i++)
1947 irq_ptr->output_qs[i]->state=state;
1952 qdio_irq_check_sense(struct subchannel_id schid, struct irb *irb)
1956 if (irb->esw.esw0.erw.cons) {
1957 sprintf(dbf_text,"sens%4x",schid.sch_no);
1958 QDIO_DBF_TEXT2(1,trace,dbf_text);
1959 QDIO_DBF_HEX0(0,sense,irb,QDIO_DBF_SENSE_LEN);
1961 QDIO_PRINT_WARN("sense data available on qdio channel.\n");
1962 QDIO_HEXDUMP16(WARN,"irb: ",irb);
1963 QDIO_HEXDUMP16(WARN,"sense data: ",irb->ecw);
1969 qdio_handle_pci(struct qdio_irq *irq_ptr)
1974 if (qdio_performance_stats) {
1976 perf_stats.start_time_inbound=NOW;
1978 for (i=0;i<irq_ptr->no_input_qs;i++) {
1979 q=irq_ptr->input_qs[i];
1980 if (q->is_input_q&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT)
1983 if (qdio_performance_stats)
1984 perf_stats.tl_runs--;
1985 __qdio_inbound_processing(q);
1988 if (!irq_ptr->hydra_gives_outbound_pcis)
1990 for (i=0;i<irq_ptr->no_output_qs;i++) {
1991 q=irq_ptr->output_qs[i];
1992 if (qdio_is_outbound_q_done(q))
1994 if (qdio_performance_stats)
1995 perf_stats.tl_runs--;
1996 if (!irq_ptr->sync_done_on_outb_pcis)
1998 __qdio_outbound_processing(q);
2002 static void qdio_establish_handle_irq(struct ccw_device*, int, int);
2005 qdio_handle_activate_check(struct ccw_device *cdev, unsigned long intparm,
2006 int cstat, int dstat)
2008 struct qdio_irq *irq_ptr;
2012 irq_ptr = cdev->private->qdio_data;
2014 QDIO_DBF_TEXT2(1, trace, "ick2");
2015 sprintf(dbf_text,"%s", cdev->dev.bus_id);
2016 QDIO_DBF_TEXT2(1,trace,dbf_text);
2017 QDIO_DBF_HEX2(0,trace,&intparm,sizeof(int));
2018 QDIO_DBF_HEX2(0,trace,&dstat,sizeof(int));
2019 QDIO_DBF_HEX2(0,trace,&cstat,sizeof(int));
2020 QDIO_PRINT_ERR("received check condition on activate " \
2021 "queues on device %s (cs=x%x, ds=x%x).\n",
2022 cdev->dev.bus_id, cstat, dstat);
2023 if (irq_ptr->no_input_qs) {
2024 q=irq_ptr->input_qs[0];
2025 } else if (irq_ptr->no_output_qs) {
2026 q=irq_ptr->output_qs[0];
2028 QDIO_PRINT_ERR("oops... no queue registered for device %s!?\n",
2030 goto omit_handler_call;
2032 q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION|
2033 QDIO_STATUS_LOOK_FOR_ERROR,
2034 0,0,0,-1,-1,q->int_parm);
2036 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_STOPPED);
2041 qdio_call_shutdown(struct work_struct *work)
2043 struct ccw_device_private *priv;
2044 struct ccw_device *cdev;
2046 priv = container_of(work, struct ccw_device_private, kick_work);
2048 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
2049 put_device(&cdev->dev);
2053 qdio_timeout_handler(struct ccw_device *cdev)
2055 struct qdio_irq *irq_ptr;
2058 QDIO_DBF_TEXT2(0, trace, "qtoh");
2059 sprintf(dbf_text, "%s", cdev->dev.bus_id);
2060 QDIO_DBF_TEXT2(0, trace, dbf_text);
2062 irq_ptr = cdev->private->qdio_data;
2063 sprintf(dbf_text, "state:%d", irq_ptr->state);
2064 QDIO_DBF_TEXT2(0, trace, dbf_text);
2066 switch (irq_ptr->state) {
2067 case QDIO_IRQ_STATE_INACTIVE:
2068 QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: timed out\n",
2069 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2070 QDIO_DBF_TEXT2(1,setup,"eq:timeo");
2071 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2073 case QDIO_IRQ_STATE_CLEANUP:
2074 QDIO_PRINT_INFO("Did not get interrupt on cleanup, "
2076 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2077 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2079 case QDIO_IRQ_STATE_ESTABLISHED:
2080 case QDIO_IRQ_STATE_ACTIVE:
2081 /* I/O has been terminated by common I/O layer. */
2082 QDIO_PRINT_INFO("Queues on irq 0.%x.%04x killed by cio.\n",
2083 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2084 QDIO_DBF_TEXT2(1, trace, "cio:term");
2085 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
2086 if (get_device(&cdev->dev)) {
2087 /* Can't call shutdown from interrupt context. */
2088 PREPARE_WORK(&cdev->private->kick_work,
2089 qdio_call_shutdown);
2090 queue_work(ccw_device_work, &cdev->private->kick_work);
2096 ccw_device_set_timeout(cdev, 0);
2097 wake_up(&cdev->private->wait_q);
2101 qdio_handler(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
2103 struct qdio_irq *irq_ptr;
2107 #ifdef CONFIG_QDIO_DEBUG
2108 QDIO_DBF_TEXT4(0, trace, "qint");
2109 sprintf(dbf_text, "%s", cdev->dev.bus_id);
2110 QDIO_DBF_TEXT4(0, trace, dbf_text);
2111 #endif /* CONFIG_QDIO_DEBUG */
2114 QDIO_PRINT_ERR("got unsolicited interrupt in qdio " \
2115 "handler, device %s\n", cdev->dev.bus_id);
2119 irq_ptr = cdev->private->qdio_data;
2121 QDIO_DBF_TEXT2(1, trace, "uint");
2122 sprintf(dbf_text,"%s", cdev->dev.bus_id);
2123 QDIO_DBF_TEXT2(1,trace,dbf_text);
2124 QDIO_PRINT_ERR("received interrupt on unused device %s!\n",
2130 /* Currently running i/o is in error. */
2131 switch (PTR_ERR(irb)) {
2133 QDIO_PRINT_ERR("i/o error on device %s\n",
2137 qdio_timeout_handler(cdev);
2140 QDIO_PRINT_ERR("unknown error state %ld on device %s\n",
2141 PTR_ERR(irb), cdev->dev.bus_id);
2146 qdio_irq_check_sense(irq_ptr->schid, irb);
2148 #ifdef CONFIG_QDIO_DEBUG
2149 sprintf(dbf_text, "state:%d", irq_ptr->state);
2150 QDIO_DBF_TEXT4(0, trace, dbf_text);
2151 #endif /* CONFIG_QDIO_DEBUG */
2153 cstat = irb->scsw.cstat;
2154 dstat = irb->scsw.dstat;
2156 switch (irq_ptr->state) {
2157 case QDIO_IRQ_STATE_INACTIVE:
2158 qdio_establish_handle_irq(cdev, cstat, dstat);
2161 case QDIO_IRQ_STATE_CLEANUP:
2162 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2165 case QDIO_IRQ_STATE_ESTABLISHED:
2166 case QDIO_IRQ_STATE_ACTIVE:
2167 if (cstat & SCHN_STAT_PCI) {
2168 qdio_handle_pci(irq_ptr);
2172 if ((cstat&~SCHN_STAT_PCI)||dstat) {
2173 qdio_handle_activate_check(cdev, intparm, cstat, dstat);
2177 QDIO_PRINT_ERR("got interrupt for queues in state %d on " \
2179 irq_ptr->state, cdev->dev.bus_id);
2181 wake_up(&cdev->private->wait_q);
2186 qdio_synchronize(struct ccw_device *cdev, unsigned int flags,
2187 unsigned int queue_number)
2191 struct qdio_irq *irq_ptr;
2193 #ifdef CONFIG_QDIO_DEBUG
2194 char dbf_text[15]="SyncXXXX";
2197 irq_ptr = cdev->private->qdio_data;
2201 #ifdef CONFIG_QDIO_DEBUG
2202 *((int*)(&dbf_text[4])) = irq_ptr->schid.sch_no;
2203 QDIO_DBF_HEX4(0,trace,dbf_text,QDIO_DBF_TRACE_LEN);
2204 *((int*)(&dbf_text[0]))=flags;
2205 *((int*)(&dbf_text[4]))=queue_number;
2206 QDIO_DBF_HEX4(0,trace,dbf_text,QDIO_DBF_TRACE_LEN);
2207 #endif /* CONFIG_QDIO_DEBUG */
2209 if (flags&QDIO_FLAG_SYNC_INPUT) {
2210 q=irq_ptr->input_qs[queue_number];
2213 if (!(irq_ptr->is_qebsm))
2214 cc = do_siga_sync(q->schid, 0, q->mask);
2215 } else if (flags&QDIO_FLAG_SYNC_OUTPUT) {
2216 q=irq_ptr->output_qs[queue_number];
2219 if (!(irq_ptr->is_qebsm))
2220 cc = do_siga_sync(q->schid, q->mask, 0);
2226 QDIO_DBF_HEX3(0,trace,&ptr,sizeof(int));
2232 qdio_check_subchannel_qebsm(struct qdio_irq *irq_ptr, unsigned char qdioac,
2233 unsigned long token)
2237 unsigned int count, start_buf;
2240 /*check if QEBSM is disabled */
2241 if (!(irq_ptr->is_qebsm) || !(qdioac & 0x01)) {
2242 irq_ptr->is_qebsm = 0;
2243 irq_ptr->sch_token = 0;
2244 irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM;
2245 QDIO_DBF_TEXT0(0,setup,"noV=V");
2248 irq_ptr->sch_token = token;
2250 for (i = 0; i < irq_ptr->no_input_qs;i++) {
2251 q = irq_ptr->input_qs[i];
2252 count = QDIO_MAX_BUFFERS_PER_Q;
2254 set_slsb(q, &start_buf, SLSB_P_INPUT_NOT_INIT, &count);
2256 sprintf(dbf_text,"V=V:%2x",irq_ptr->is_qebsm);
2257 QDIO_DBF_TEXT0(0,setup,dbf_text);
2258 sprintf(dbf_text,"%8lx",irq_ptr->sch_token);
2259 QDIO_DBF_TEXT0(0,setup,dbf_text);
2261 for (i = 0; i < irq_ptr->no_output_qs; i++) {
2262 q = irq_ptr->output_qs[i];
2263 count = QDIO_MAX_BUFFERS_PER_Q;
2265 set_slsb(q, &start_buf, SLSB_P_OUTPUT_NOT_INIT, &count);
2270 qdio_get_ssqd_information(struct qdio_irq *irq_ptr)
2273 unsigned char qdioac;
2275 struct chsc_header request;
2283 struct chsc_header response;
2302 QDIO_DBF_TEXT0(0,setup,"getssqd");
2304 ssqd_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC);
2306 QDIO_PRINT_WARN("Could not get memory for chsc. Using all " \
2307 "SIGAs for sch x%x.\n", irq_ptr->schid.sch_no);
2308 irq_ptr->qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY ||
2309 CHSC_FLAG_SIGA_OUTPUT_NECESSARY ||
2310 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */
2311 irq_ptr->is_qebsm = 0;
2312 irq_ptr->sch_token = 0;
2313 irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM;
2317 ssqd_area->request = (struct chsc_header) {
2321 ssqd_area->first_sch = irq_ptr->schid.sch_no;
2322 ssqd_area->last_sch = irq_ptr->schid.sch_no;
2323 ssqd_area->ssid = irq_ptr->schid.ssid;
2324 result = chsc(ssqd_area);
2327 QDIO_PRINT_WARN("CHSC returned cc %i. Using all " \
2328 "SIGAs for sch 0.%x.%x.\n", result,
2329 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2330 qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY ||
2331 CHSC_FLAG_SIGA_OUTPUT_NECESSARY ||
2332 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */
2333 irq_ptr->is_qebsm = 0;
2337 if (ssqd_area->response.code != QDIO_CHSC_RESPONSE_CODE_OK) {
2338 QDIO_PRINT_WARN("response upon checking SIGA needs " \
2339 "is 0x%x. Using all SIGAs for sch 0.%x.%x.\n",
2340 ssqd_area->response.code,
2341 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2342 qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY ||
2343 CHSC_FLAG_SIGA_OUTPUT_NECESSARY ||
2344 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */
2345 irq_ptr->is_qebsm = 0;
2348 if (!(ssqd_area->flags & CHSC_FLAG_QDIO_CAPABILITY) ||
2349 !(ssqd_area->flags & CHSC_FLAG_VALIDITY) ||
2350 (ssqd_area->sch != irq_ptr->schid.sch_no)) {
2351 QDIO_PRINT_WARN("huh? problems checking out sch 0.%x.%x... " \
2352 "using all SIGAs.\n",
2353 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2354 qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY |
2355 CHSC_FLAG_SIGA_OUTPUT_NECESSARY |
2356 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* worst case */
2357 irq_ptr->is_qebsm = 0;
2360 qdioac = ssqd_area->qdioac1;
2362 qdio_check_subchannel_qebsm(irq_ptr, qdioac,
2363 ssqd_area->sch_token);
2364 mempool_free(ssqd_area, qdio_mempool_scssc);
2365 irq_ptr->qdioac = qdioac;
2369 tiqdio_check_chsc_availability(void)
2373 if (!css_characteristics_avail)
2376 /* Check for bit 41. */
2377 if (!css_general_characteristics.aif) {
2378 QDIO_PRINT_WARN("Adapter interruption facility not " \
2383 /* Check for bits 107 and 108. */
2384 if (!css_chsc_characteristics.scssc ||
2385 !css_chsc_characteristics.scsscf) {
2386 QDIO_PRINT_WARN("Set Chan Subsys. Char. & Fast-CHSCs " \
2387 "not available.\n");
2391 /* Check for OSA/FCP thin interrupts (bit 67). */
2392 hydra_thinints = css_general_characteristics.aif_osa;
2393 sprintf(dbf_text,"hydrati%1x", hydra_thinints);
2394 QDIO_DBF_TEXT0(0,setup,dbf_text);
2397 /* Check for QEBSM support in general (bit 58). */
2398 is_passthrough = css_general_characteristics.qebsm;
2400 sprintf(dbf_text,"cssQBS:%1x", is_passthrough);
2401 QDIO_DBF_TEXT0(0,setup,dbf_text);
2403 /* Check for aif time delay disablement fac (bit 56). If installed,
2404 * omit svs even under lpar (good point by rick again) */
2405 omit_svs = css_general_characteristics.aif_tdd;
2406 sprintf(dbf_text,"omitsvs%1x", omit_svs);
2407 QDIO_DBF_TEXT0(0,setup,dbf_text);
2413 tiqdio_set_subchannel_ind(struct qdio_irq *irq_ptr, int reset_to_zero)
2415 unsigned long real_addr_local_summary_bit;
2416 unsigned long real_addr_dev_st_chg_ind;
2420 unsigned int resp_code;
2424 struct chsc_header request;
2429 u64 summary_indicator_addr;
2430 u64 subchannel_indicator_addr;
2435 u32 word_with_d_bit;
2436 /* set to 0x10000000 to enable
2437 * time delay disablement facility */
2439 struct subchannel_id schid;
2440 u32 reserved6[1004];
2441 struct chsc_header response;
2445 if (!irq_ptr->is_thinint_irq)
2448 if (reset_to_zero) {
2449 real_addr_local_summary_bit=0;
2450 real_addr_dev_st_chg_ind=0;
2452 real_addr_local_summary_bit=
2453 virt_to_phys((volatile void *)indicators);
2454 real_addr_dev_st_chg_ind=
2455 virt_to_phys((volatile void *)irq_ptr->dev_st_chg_ind);
2458 scssc_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC);
2460 QDIO_PRINT_WARN("No memory for setting indicators on " \
2461 "subchannel 0.%x.%x.\n",
2462 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2465 scssc_area->request = (struct chsc_header) {
2469 scssc_area->operation_code = 0;
2471 scssc_area->summary_indicator_addr = real_addr_local_summary_bit;
2472 scssc_area->subchannel_indicator_addr = real_addr_dev_st_chg_ind;
2473 scssc_area->ks = QDIO_STORAGE_KEY;
2474 scssc_area->kc = QDIO_STORAGE_KEY;
2475 scssc_area->isc = TIQDIO_THININT_ISC;
2476 scssc_area->schid = irq_ptr->schid;
2477 /* enables the time delay disablement facility. Don't care
2478 * whether it is really there (i.e. we haven't checked for
2480 if (css_general_characteristics.aif_tdd)
2481 scssc_area->word_with_d_bit = 0x10000000;
2483 QDIO_PRINT_WARN("Time delay disablement facility " \
2486 result = chsc(scssc_area);
2488 QDIO_PRINT_WARN("could not set indicators on irq 0.%x.%x, " \
2490 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,result);
2495 resp_code = scssc_area->response.code;
2496 if (resp_code!=QDIO_CHSC_RESPONSE_CODE_OK) {
2497 QDIO_PRINT_WARN("response upon setting indicators " \
2498 "is 0x%x.\n",resp_code);
2499 sprintf(dbf_text,"sidR%4x",resp_code);
2500 QDIO_DBF_TEXT1(0,trace,dbf_text);
2501 QDIO_DBF_TEXT1(0,setup,dbf_text);
2502 ptr=&scssc_area->response;
2503 QDIO_DBF_HEX2(1,setup,&ptr,QDIO_DBF_SETUP_LEN);
2508 QDIO_DBF_TEXT2(0,setup,"setscind");
2509 QDIO_DBF_HEX2(0,setup,&real_addr_local_summary_bit,
2510 sizeof(unsigned long));
2511 QDIO_DBF_HEX2(0,setup,&real_addr_dev_st_chg_ind,sizeof(unsigned long));
2514 mempool_free(scssc_area, qdio_mempool_scssc);
2520 tiqdio_set_delay_target(struct qdio_irq *irq_ptr, unsigned long delay_target)
2522 unsigned int resp_code;
2528 struct chsc_header request;
2535 u32 reserved5[1009];
2536 struct chsc_header response;
2540 if (!irq_ptr->is_thinint_irq)
2543 scsscf_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC);
2545 QDIO_PRINT_WARN("No memory for setting delay target on " \
2546 "subchannel 0.%x.%x.\n",
2547 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2550 scsscf_area->request = (struct chsc_header) {
2555 scsscf_area->delay_target = delay_target<<16;
2557 result=chsc(scsscf_area);
2559 QDIO_PRINT_WARN("could not set delay target on irq 0.%x.%x, " \
2560 "cc=%i. Continuing.\n",
2561 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
2567 resp_code = scsscf_area->response.code;
2568 if (resp_code!=QDIO_CHSC_RESPONSE_CODE_OK) {
2569 QDIO_PRINT_WARN("response upon setting delay target " \
2570 "is 0x%x. Continuing.\n",resp_code);
2571 sprintf(dbf_text,"sdtR%4x",resp_code);
2572 QDIO_DBF_TEXT1(0,trace,dbf_text);
2573 QDIO_DBF_TEXT1(0,setup,dbf_text);
2574 ptr=&scsscf_area->response;
2575 QDIO_DBF_HEX2(1,trace,&ptr,QDIO_DBF_TRACE_LEN);
2577 QDIO_DBF_TEXT2(0,trace,"delytrgt");
2578 QDIO_DBF_HEX2(0,trace,&delay_target,sizeof(unsigned long));
2579 result = 0; /* not critical */
2581 mempool_free(scsscf_area, qdio_mempool_scssc);
2586 qdio_cleanup(struct ccw_device *cdev, int how)
2588 struct qdio_irq *irq_ptr;
2592 irq_ptr = cdev->private->qdio_data;
2596 sprintf(dbf_text,"qcln%4x",irq_ptr->schid.sch_no);
2597 QDIO_DBF_TEXT1(0,trace,dbf_text);
2598 QDIO_DBF_TEXT0(0,setup,dbf_text);
2600 rc = qdio_shutdown(cdev, how);
2601 if ((rc == 0) || (rc == -EINPROGRESS))
2602 rc = qdio_free(cdev);
2607 qdio_shutdown(struct ccw_device *cdev, int how)
2609 struct qdio_irq *irq_ptr;
2613 unsigned long flags;
2617 irq_ptr = cdev->private->qdio_data;
2621 down(&irq_ptr->setting_up_sema);
2623 sprintf(dbf_text,"qsqs%4x",irq_ptr->schid.sch_no);
2624 QDIO_DBF_TEXT1(0,trace,dbf_text);
2625 QDIO_DBF_TEXT0(0,setup,dbf_text);
2627 /* mark all qs as uninteresting */
2628 for (i=0;i<irq_ptr->no_input_qs;i++)
2629 atomic_set(&irq_ptr->input_qs[i]->is_in_shutdown,1);
2631 for (i=0;i<irq_ptr->no_output_qs;i++)
2632 atomic_set(&irq_ptr->output_qs[i]->is_in_shutdown,1);
2634 tasklet_kill(&tiqdio_tasklet);
2636 for (i=0;i<irq_ptr->no_input_qs;i++) {
2637 qdio_unmark_q(irq_ptr->input_qs[i]);
2638 tasklet_kill(&irq_ptr->input_qs[i]->tasklet);
2639 wait_event_interruptible_timeout(cdev->private->wait_q,
2640 !atomic_read(&irq_ptr->
2643 QDIO_NO_USE_COUNT_TIMEOUT);
2644 if (atomic_read(&irq_ptr->input_qs[i]->use_count))
2645 result=-EINPROGRESS;
2648 for (i=0;i<irq_ptr->no_output_qs;i++) {
2649 tasklet_kill(&irq_ptr->output_qs[i]->tasklet);
2650 wait_event_interruptible_timeout(cdev->private->wait_q,
2651 !atomic_read(&irq_ptr->
2654 QDIO_NO_USE_COUNT_TIMEOUT);
2655 if (atomic_read(&irq_ptr->output_qs[i]->use_count))
2656 result=-EINPROGRESS;
2659 /* cleanup subchannel */
2660 spin_lock_irqsave(get_ccwdev_lock(cdev),flags);
2661 if (how&QDIO_FLAG_CLEANUP_USING_CLEAR) {
2662 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
2663 timeout=QDIO_CLEANUP_CLEAR_TIMEOUT;
2664 } else if (how&QDIO_FLAG_CLEANUP_USING_HALT) {
2665 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
2666 timeout=QDIO_CLEANUP_HALT_TIMEOUT;
2667 } else { /* default behaviour */
2668 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
2669 timeout=QDIO_CLEANUP_HALT_TIMEOUT;
2671 if (rc == -ENODEV) {
2672 /* No need to wait for device no longer present. */
2673 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2674 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2675 } else if (((void *)cdev->handler != (void *)qdio_handler) && rc == 0) {
2677 * Whoever put another handler there, has to cope with the
2678 * interrupt theirself. Might happen if qdio_shutdown was
2679 * called on already shutdown queues, but this shouldn't have
2682 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2683 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2684 } else if (rc == 0) {
2685 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
2686 ccw_device_set_timeout(cdev, timeout);
2687 spin_unlock_irqrestore(get_ccwdev_lock(cdev),flags);
2689 wait_event(cdev->private->wait_q,
2690 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
2691 irq_ptr->state == QDIO_IRQ_STATE_ERR);
2693 QDIO_PRINT_INFO("ccw_device_{halt,clear} returned %d for "
2694 "device %s\n", result, cdev->dev.bus_id);
2695 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2699 if (irq_ptr->is_thinint_irq) {
2700 qdio_put_indicator((__u32*)irq_ptr->dev_st_chg_ind);
2701 tiqdio_set_subchannel_ind(irq_ptr,1);
2702 /* reset adapter interrupt indicators */
2705 /* exchange int handlers, if necessary */
2706 if ((void*)cdev->handler == (void*)qdio_handler)
2707 cdev->handler=irq_ptr->original_int_handler;
2709 /* Ignore errors. */
2710 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2711 ccw_device_set_timeout(cdev, 0);
2713 up(&irq_ptr->setting_up_sema);
2718 qdio_free(struct ccw_device *cdev)
2720 struct qdio_irq *irq_ptr;
2723 irq_ptr = cdev->private->qdio_data;
2727 down(&irq_ptr->setting_up_sema);
2729 sprintf(dbf_text,"qfqs%4x",irq_ptr->schid.sch_no);
2730 QDIO_DBF_TEXT1(0,trace,dbf_text);
2731 QDIO_DBF_TEXT0(0,setup,dbf_text);
2733 cdev->private->qdio_data = NULL;
2735 up(&irq_ptr->setting_up_sema);
2737 qdio_release_irq_memory(irq_ptr);
2738 module_put(THIS_MODULE);
2743 qdio_allocate_do_dbf(struct qdio_initialize *init_data)
2745 char dbf_text[20]; /* if a printf printed out more than 8 chars */
2747 sprintf(dbf_text,"qfmt:%x",init_data->q_format);
2748 QDIO_DBF_TEXT0(0,setup,dbf_text);
2749 QDIO_DBF_HEX0(0,setup,init_data->adapter_name,8);
2750 sprintf(dbf_text,"qpff%4x",init_data->qib_param_field_format);
2751 QDIO_DBF_TEXT0(0,setup,dbf_text);
2752 QDIO_DBF_HEX0(0,setup,&init_data->qib_param_field,sizeof(char*));
2753 QDIO_DBF_HEX0(0,setup,&init_data->input_slib_elements,sizeof(long*));
2754 QDIO_DBF_HEX0(0,setup,&init_data->output_slib_elements,sizeof(long*));
2755 sprintf(dbf_text,"miit%4x",init_data->min_input_threshold);
2756 QDIO_DBF_TEXT0(0,setup,dbf_text);
2757 sprintf(dbf_text,"mait%4x",init_data->max_input_threshold);
2758 QDIO_DBF_TEXT0(0,setup,dbf_text);
2759 sprintf(dbf_text,"miot%4x",init_data->min_output_threshold);
2760 QDIO_DBF_TEXT0(0,setup,dbf_text);
2761 sprintf(dbf_text,"maot%4x",init_data->max_output_threshold);
2762 QDIO_DBF_TEXT0(0,setup,dbf_text);
2763 sprintf(dbf_text,"niq:%4x",init_data->no_input_qs);
2764 QDIO_DBF_TEXT0(0,setup,dbf_text);
2765 sprintf(dbf_text,"noq:%4x",init_data->no_output_qs);
2766 QDIO_DBF_TEXT0(0,setup,dbf_text);
2767 QDIO_DBF_HEX0(0,setup,&init_data->input_handler,sizeof(void*));
2768 QDIO_DBF_HEX0(0,setup,&init_data->output_handler,sizeof(void*));
2769 QDIO_DBF_HEX0(0,setup,&init_data->int_parm,sizeof(long));
2770 QDIO_DBF_HEX0(0,setup,&init_data->flags,sizeof(long));
2771 QDIO_DBF_HEX0(0,setup,&init_data->input_sbal_addr_array,sizeof(void*));
2772 QDIO_DBF_HEX0(0,setup,&init_data->output_sbal_addr_array,sizeof(void*));
2776 qdio_allocate_fill_input_desc(struct qdio_irq *irq_ptr, int i, int iqfmt)
2778 irq_ptr->input_qs[i]->is_iqdio_q = iqfmt;
2779 irq_ptr->input_qs[i]->is_thinint_q = irq_ptr->is_thinint_irq;
2781 irq_ptr->qdr->qdf0[i].sliba=(unsigned long)(irq_ptr->input_qs[i]->slib);
2783 irq_ptr->qdr->qdf0[i].sla=(unsigned long)(irq_ptr->input_qs[i]->sl);
2785 irq_ptr->qdr->qdf0[i].slsba=
2786 (unsigned long)(&irq_ptr->input_qs[i]->slsb.acc.val[0]);
2788 irq_ptr->qdr->qdf0[i].akey=QDIO_STORAGE_KEY;
2789 irq_ptr->qdr->qdf0[i].bkey=QDIO_STORAGE_KEY;
2790 irq_ptr->qdr->qdf0[i].ckey=QDIO_STORAGE_KEY;
2791 irq_ptr->qdr->qdf0[i].dkey=QDIO_STORAGE_KEY;
2795 qdio_allocate_fill_output_desc(struct qdio_irq *irq_ptr, int i,
2798 irq_ptr->output_qs[i]->is_iqdio_q = iqfmt;
2799 irq_ptr->output_qs[i]->is_thinint_q = irq_ptr->is_thinint_irq;
2801 irq_ptr->qdr->qdf0[i+j].sliba=(unsigned long)(irq_ptr->output_qs[i]->slib);
2803 irq_ptr->qdr->qdf0[i+j].sla=(unsigned long)(irq_ptr->output_qs[i]->sl);
2805 irq_ptr->qdr->qdf0[i+j].slsba=
2806 (unsigned long)(&irq_ptr->output_qs[i]->slsb.acc.val[0]);
2808 irq_ptr->qdr->qdf0[i+j].akey=QDIO_STORAGE_KEY;
2809 irq_ptr->qdr->qdf0[i+j].bkey=QDIO_STORAGE_KEY;
2810 irq_ptr->qdr->qdf0[i+j].ckey=QDIO_STORAGE_KEY;
2811 irq_ptr->qdr->qdf0[i+j].dkey=QDIO_STORAGE_KEY;
2816 qdio_initialize_set_siga_flags_input(struct qdio_irq *irq_ptr)
2820 for (i=0;i<irq_ptr->no_input_qs;i++) {
2821 irq_ptr->input_qs[i]->siga_sync=
2822 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY;
2823 irq_ptr->input_qs[i]->siga_in=
2824 irq_ptr->qdioac&CHSC_FLAG_SIGA_INPUT_NECESSARY;
2825 irq_ptr->input_qs[i]->siga_out=
2826 irq_ptr->qdioac&CHSC_FLAG_SIGA_OUTPUT_NECESSARY;
2827 irq_ptr->input_qs[i]->siga_sync_done_on_thinints=
2828 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS;
2829 irq_ptr->input_qs[i]->hydra_gives_outbound_pcis=
2830 irq_ptr->hydra_gives_outbound_pcis;
2831 irq_ptr->input_qs[i]->siga_sync_done_on_outb_tis=
2833 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2834 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS))==
2835 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2836 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS));
2842 qdio_initialize_set_siga_flags_output(struct qdio_irq *irq_ptr)
2846 for (i=0;i<irq_ptr->no_output_qs;i++) {
2847 irq_ptr->output_qs[i]->siga_sync=
2848 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY;
2849 irq_ptr->output_qs[i]->siga_in=
2850 irq_ptr->qdioac&CHSC_FLAG_SIGA_INPUT_NECESSARY;
2851 irq_ptr->output_qs[i]->siga_out=
2852 irq_ptr->qdioac&CHSC_FLAG_SIGA_OUTPUT_NECESSARY;
2853 irq_ptr->output_qs[i]->siga_sync_done_on_thinints=
2854 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS;
2855 irq_ptr->output_qs[i]->hydra_gives_outbound_pcis=
2856 irq_ptr->hydra_gives_outbound_pcis;
2857 irq_ptr->output_qs[i]->siga_sync_done_on_outb_tis=
2859 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2860 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS))==
2861 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2862 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS));
2868 qdio_establish_irq_check_for_errors(struct ccw_device *cdev, int cstat,
2872 struct qdio_irq *irq_ptr;
2874 irq_ptr = cdev->private->qdio_data;
2876 if (cstat || (dstat & ~(DEV_STAT_CHN_END|DEV_STAT_DEV_END))) {
2877 sprintf(dbf_text,"ick1%4x",irq_ptr->schid.sch_no);
2878 QDIO_DBF_TEXT2(1,trace,dbf_text);
2879 QDIO_DBF_HEX2(0,trace,&dstat,sizeof(int));
2880 QDIO_DBF_HEX2(0,trace,&cstat,sizeof(int));
2881 QDIO_PRINT_ERR("received check condition on establish " \
2882 "queues on irq 0.%x.%x (cs=x%x, ds=x%x).\n",
2883 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
2885 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ERR);
2888 if (!(dstat & DEV_STAT_DEV_END)) {
2889 QDIO_DBF_TEXT2(1,setup,"eq:no de");
2890 QDIO_DBF_HEX2(0,setup,&dstat, sizeof(dstat));
2891 QDIO_DBF_HEX2(0,setup,&cstat, sizeof(cstat));
2892 QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: didn't get "
2893 "device end: dstat=%02x, cstat=%02x\n",
2894 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
2896 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2900 if (dstat & ~(DEV_STAT_CHN_END|DEV_STAT_DEV_END)) {
2901 QDIO_DBF_TEXT2(1,setup,"eq:badio");
2902 QDIO_DBF_HEX2(0,setup,&dstat, sizeof(dstat));
2903 QDIO_DBF_HEX2(0,setup,&cstat, sizeof(cstat));
2904 QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: got "
2905 "the following devstat: dstat=%02x, "
2906 "cstat=%02x\n", irq_ptr->schid.ssid,
2907 irq_ptr->schid.sch_no, dstat, cstat);
2908 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2915 qdio_establish_handle_irq(struct ccw_device *cdev, int cstat, int dstat)
2917 struct qdio_irq *irq_ptr;
2920 irq_ptr = cdev->private->qdio_data;
2922 sprintf(dbf_text,"qehi%4x",cdev->private->schid.sch_no);
2923 QDIO_DBF_TEXT0(0,setup,dbf_text);
2924 QDIO_DBF_TEXT0(0,trace,dbf_text);
2926 if (qdio_establish_irq_check_for_errors(cdev, cstat, dstat)) {
2927 ccw_device_set_timeout(cdev, 0);
2931 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ESTABLISHED);
2932 ccw_device_set_timeout(cdev, 0);
2936 qdio_initialize(struct qdio_initialize *init_data)
2941 sprintf(dbf_text,"qini%4x",init_data->cdev->private->schid.sch_no);
2942 QDIO_DBF_TEXT0(0,setup,dbf_text);
2943 QDIO_DBF_TEXT0(0,trace,dbf_text);
2945 rc = qdio_allocate(init_data);
2947 rc = qdio_establish(init_data);
2949 qdio_free(init_data->cdev);
2957 qdio_allocate(struct qdio_initialize *init_data)
2959 struct qdio_irq *irq_ptr;
2962 sprintf(dbf_text,"qalc%4x",init_data->cdev->private->schid.sch_no);
2963 QDIO_DBF_TEXT0(0,setup,dbf_text);
2964 QDIO_DBF_TEXT0(0,trace,dbf_text);
2965 if ( (init_data->no_input_qs>QDIO_MAX_QUEUES_PER_IRQ) ||
2966 (init_data->no_output_qs>QDIO_MAX_QUEUES_PER_IRQ) ||
2967 ((init_data->no_input_qs) && (!init_data->input_handler)) ||
2968 ((init_data->no_output_qs) && (!init_data->output_handler)) )
2971 if (!init_data->input_sbal_addr_array)
2974 if (!init_data->output_sbal_addr_array)
2977 qdio_allocate_do_dbf(init_data);
2980 irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
2982 QDIO_DBF_TEXT0(0,setup,"irq_ptr:");
2983 QDIO_DBF_HEX0(0,setup,&irq_ptr,sizeof(void*));
2986 QDIO_PRINT_ERR("kmalloc of irq_ptr failed!\n");
2990 init_MUTEX(&irq_ptr->setting_up_sema);
2992 /* QDR must be in DMA area since CCW data address is only 32 bit */
2993 irq_ptr->qdr=kmalloc(sizeof(struct qdr), GFP_KERNEL | GFP_DMA);
2994 if (!(irq_ptr->qdr)) {
2995 free_page((unsigned long) irq_ptr);
2996 QDIO_PRINT_ERR("kmalloc of irq_ptr->qdr failed!\n");
2999 QDIO_DBF_TEXT0(0,setup,"qdr:");
3000 QDIO_DBF_HEX0(0,setup,&irq_ptr->qdr,sizeof(void*));
3002 if (qdio_alloc_qs(irq_ptr,
3003 init_data->no_input_qs,
3004 init_data->no_output_qs)) {
3005 qdio_release_irq_memory(irq_ptr);
3009 init_data->cdev->private->qdio_data = irq_ptr;
3011 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_INACTIVE);
3016 static int qdio_fill_irq(struct qdio_initialize *init_data)
3022 struct qdio_irq *irq_ptr;
3024 irq_ptr = init_data->cdev->private->qdio_data;
3026 memset(irq_ptr,0,((char*)&irq_ptr->qdr)-((char*)irq_ptr));
3028 /* wipes qib.ac, required by ar7063 */
3029 memset(irq_ptr->qdr,0,sizeof(struct qdr));
3031 irq_ptr->int_parm=init_data->int_parm;
3033 irq_ptr->schid = ccw_device_get_subchannel_id(init_data->cdev);
3034 irq_ptr->no_input_qs=init_data->no_input_qs;
3035 irq_ptr->no_output_qs=init_data->no_output_qs;
3037 if (init_data->q_format==QDIO_IQDIO_QFMT) {
3038 irq_ptr->is_iqdio_irq=1;
3039 irq_ptr->is_thinint_irq=1;
3041 irq_ptr->is_iqdio_irq=0;
3042 irq_ptr->is_thinint_irq=hydra_thinints;
3044 sprintf(dbf_text,"is_i_t%1x%1x",
3045 irq_ptr->is_iqdio_irq,irq_ptr->is_thinint_irq);
3046 QDIO_DBF_TEXT2(0,setup,dbf_text);
3048 if (irq_ptr->is_thinint_irq) {
3049 irq_ptr->dev_st_chg_ind = qdio_get_indicator();
3050 QDIO_DBF_HEX1(0,setup,&irq_ptr->dev_st_chg_ind,sizeof(void*));
3051 if (!irq_ptr->dev_st_chg_ind) {
3052 QDIO_PRINT_WARN("no indicator location available " \
3053 "for irq 0.%x.%x\n",
3054 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
3055 qdio_release_irq_memory(irq_ptr);
3061 irq_ptr->equeue.cmd=DEFAULT_ESTABLISH_QS_CMD;
3062 irq_ptr->equeue.count=DEFAULT_ESTABLISH_QS_COUNT;
3063 irq_ptr->aqueue.cmd=DEFAULT_ACTIVATE_QS_CMD;
3064 irq_ptr->aqueue.count=DEFAULT_ACTIVATE_QS_COUNT;
3066 qdio_fill_qs(irq_ptr, init_data->cdev,
3067 init_data->no_input_qs,
3068 init_data->no_output_qs,
3069 init_data->input_handler,
3070 init_data->output_handler,init_data->int_parm,
3071 init_data->q_format,init_data->flags,
3072 init_data->input_sbal_addr_array,
3073 init_data->output_sbal_addr_array);
3075 if (!try_module_get(THIS_MODULE)) {
3076 QDIO_PRINT_CRIT("try_module_get() failed!\n");
3077 qdio_release_irq_memory(irq_ptr);
3081 qdio_fill_thresholds(irq_ptr,init_data->no_input_qs,
3082 init_data->no_output_qs,
3083 init_data->min_input_threshold,
3084 init_data->max_input_threshold,
3085 init_data->min_output_threshold,
3086 init_data->max_output_threshold);
3089 irq_ptr->qdr->qfmt=init_data->q_format;
3090 irq_ptr->qdr->iqdcnt=init_data->no_input_qs;
3091 irq_ptr->qdr->oqdcnt=init_data->no_output_qs;
3092 irq_ptr->qdr->iqdsz=sizeof(struct qdesfmt0)/4; /* size in words */
3093 irq_ptr->qdr->oqdsz=sizeof(struct qdesfmt0)/4;
3095 irq_ptr->qdr->qiba=(unsigned long)&irq_ptr->qib;
3096 irq_ptr->qdr->qkey=QDIO_STORAGE_KEY;
3099 irq_ptr->is_qebsm = is_passthrough;
3100 if (irq_ptr->is_qebsm)
3101 irq_ptr->qib.rflags |= QIB_RFLAGS_ENABLE_QEBSM;
3103 irq_ptr->qib.qfmt=init_data->q_format;
3104 if (init_data->no_input_qs)
3105 irq_ptr->qib.isliba=(unsigned long)(irq_ptr->input_qs[0]->slib);
3106 if (init_data->no_output_qs)
3107 irq_ptr->qib.osliba=(unsigned long)(irq_ptr->output_qs[0]->slib);
3108 memcpy(irq_ptr->qib.ebcnam,init_data->adapter_name,8);
3110 qdio_set_impl_params(irq_ptr,init_data->qib_param_field_format,
3111 init_data->qib_param_field,
3112 init_data->no_input_qs,
3113 init_data->no_output_qs,
3114 init_data->input_slib_elements,
3115 init_data->output_slib_elements);
3117 /* first input descriptors, then output descriptors */
3118 is_iqdio = (init_data->q_format == QDIO_IQDIO_QFMT) ? 1 : 0;
3119 for (i=0;i<init_data->no_input_qs;i++)
3120 qdio_allocate_fill_input_desc(irq_ptr, i, is_iqdio);
3122 for (i=0;i<init_data->no_output_qs;i++)
3123 qdio_allocate_fill_output_desc(irq_ptr, i,
3124 init_data->no_input_qs,
3127 /* qdr, qib, sls, slsbs, slibs, sbales filled. */
3129 /* get qdio commands */
3130 ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_EQUEUE);
3132 QDIO_DBF_TEXT2(1,setup,"no eq");
3133 QDIO_PRINT_INFO("No equeue CIW found for QDIO commands. "
3134 "Trying to use default.\n");
3136 irq_ptr->equeue = *ciw;
3137 ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_AQUEUE);
3139 QDIO_DBF_TEXT2(1,setup,"no aq");
3140 QDIO_PRINT_INFO("No aqueue CIW found for QDIO commands. "
3141 "Trying to use default.\n");
3143 irq_ptr->aqueue = *ciw;
3145 /* Set new interrupt handler. */
3146 irq_ptr->original_int_handler = init_data->cdev->handler;
3147 init_data->cdev->handler = qdio_handler;
3153 qdio_establish(struct qdio_initialize *init_data)
3155 struct qdio_irq *irq_ptr;
3156 unsigned long saveflags;
3157 int result, result2;
3158 struct ccw_device *cdev;
3161 cdev=init_data->cdev;
3162 irq_ptr = cdev->private->qdio_data;
3166 if (cdev->private->state != DEV_STATE_ONLINE)
3169 down(&irq_ptr->setting_up_sema);
3171 qdio_fill_irq(init_data);
3173 /* the thinint CHSC stuff */
3174 if (irq_ptr->is_thinint_irq) {
3176 result = tiqdio_set_subchannel_ind(irq_ptr,0);
3178 up(&irq_ptr->setting_up_sema);
3179 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
3182 tiqdio_set_delay_target(irq_ptr,TIQDIO_DELAY_TARGET);
3185 sprintf(dbf_text,"qest%4x",cdev->private->schid.sch_no);
3186 QDIO_DBF_TEXT0(0,setup,dbf_text);
3187 QDIO_DBF_TEXT0(0,trace,dbf_text);
3190 irq_ptr->ccw.cmd_code=irq_ptr->equeue.cmd;
3191 irq_ptr->ccw.flags=CCW_FLAG_SLI;
3192 irq_ptr->ccw.count=irq_ptr->equeue.count;
3193 irq_ptr->ccw.cda=QDIO_GET_ADDR(irq_ptr->qdr);
3195 spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags);
3197 ccw_device_set_options_mask(cdev, 0);
3198 result=ccw_device_start_timeout(cdev,&irq_ptr->ccw,
3199 QDIO_DOING_ESTABLISH,0, 0,
3200 QDIO_ESTABLISH_TIMEOUT);
3202 result2=ccw_device_start_timeout(cdev,&irq_ptr->ccw,
3203 QDIO_DOING_ESTABLISH,0,0,
3204 QDIO_ESTABLISH_TIMEOUT);
3205 sprintf(dbf_text,"eq:io%4x",result);
3206 QDIO_DBF_TEXT2(1,setup,dbf_text);
3208 sprintf(dbf_text,"eq:io%4x",result);
3209 QDIO_DBF_TEXT2(1,setup,dbf_text);
3211 QDIO_PRINT_WARN("establish queues on irq 0.%x.%04x: do_IO " \
3212 "returned %i, next try returned %i\n",
3213 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
3217 ccw_device_set_timeout(cdev, 0);
3220 spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags);
3223 up(&irq_ptr->setting_up_sema);
3224 qdio_shutdown(cdev,QDIO_FLAG_CLEANUP_USING_CLEAR);
3228 /* Timeout is cared for already by using ccw_device_start_timeout(). */
3229 wait_event_interruptible(cdev->private->wait_q,
3230 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
3231 irq_ptr->state == QDIO_IRQ_STATE_ERR);
3233 if (irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED)
3236 up(&irq_ptr->setting_up_sema);
3237 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
3241 qdio_get_ssqd_information(irq_ptr);
3242 /* if this gets set once, we're running under VM and can omit SVSes */
3243 if (irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY)
3246 sprintf(dbf_text,"qdioac%2x",irq_ptr->qdioac);
3247 QDIO_DBF_TEXT2(0,setup,dbf_text);
3249 sprintf(dbf_text,"qib ac%2x",irq_ptr->qib.ac);
3250 QDIO_DBF_TEXT2(0,setup,dbf_text);
3252 irq_ptr->hydra_gives_outbound_pcis=
3253 irq_ptr->qib.ac&QIB_AC_OUTBOUND_PCI_SUPPORTED;
3254 irq_ptr->sync_done_on_outb_pcis=
3255 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS;
3257 qdio_initialize_set_siga_flags_input(irq_ptr);
3258 qdio_initialize_set_siga_flags_output(irq_ptr);
3260 up(&irq_ptr->setting_up_sema);
3267 qdio_activate(struct ccw_device *cdev, int flags)
3269 struct qdio_irq *irq_ptr;
3270 int i,result=0,result2;
3271 unsigned long saveflags;
3272 char dbf_text[20]; /* see qdio_initialize */
3274 irq_ptr = cdev->private->qdio_data;
3278 if (cdev->private->state != DEV_STATE_ONLINE)
3281 down(&irq_ptr->setting_up_sema);
3282 if (irq_ptr->state==QDIO_IRQ_STATE_INACTIVE) {
3287 sprintf(dbf_text,"qact%4x", irq_ptr->schid.sch_no);
3288 QDIO_DBF_TEXT2(0,setup,dbf_text);
3289 QDIO_DBF_TEXT2(0,trace,dbf_text);
3292 irq_ptr->ccw.cmd_code=irq_ptr->aqueue.cmd;
3293 irq_ptr->ccw.flags=CCW_FLAG_SLI;
3294 irq_ptr->ccw.count=irq_ptr->aqueue.count;
3295 irq_ptr->ccw.cda=QDIO_GET_ADDR(0);
3297 spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags);
3299 ccw_device_set_timeout(cdev, 0);
3300 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
3301 result=ccw_device_start(cdev,&irq_ptr->ccw,QDIO_DOING_ACTIVATE,
3302 0, DOIO_DENY_PREFETCH);
3304 result2=ccw_device_start(cdev,&irq_ptr->ccw,
3305 QDIO_DOING_ACTIVATE,0,0);
3306 sprintf(dbf_text,"aq:io%4x",result);
3307 QDIO_DBF_TEXT2(1,setup,dbf_text);
3309 sprintf(dbf_text,"aq:io%4x",result);
3310 QDIO_DBF_TEXT2(1,setup,dbf_text);
3312 QDIO_PRINT_WARN("activate queues on irq 0.%x.%04x: do_IO " \
3313 "returned %i, next try returned %i\n",
3314 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
3319 spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags);
3323 for (i=0;i<irq_ptr->no_input_qs;i++) {
3324 if (irq_ptr->is_thinint_irq) {
3326 * that way we know, that, if we will get interrupted
3327 * by tiqdio_inbound_processing, qdio_unmark_q will
3330 qdio_reserve_q(irq_ptr->input_qs[i]);
3331 qdio_mark_tiq(irq_ptr->input_qs[i]);
3332 qdio_release_q(irq_ptr->input_qs[i]);
3336 if (flags&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT) {
3337 for (i=0;i<irq_ptr->no_input_qs;i++) {
3338 irq_ptr->input_qs[i]->is_input_q|=
3339 QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT;
3343 wait_event_interruptible_timeout(cdev->private->wait_q,
3345 QDIO_IRQ_STATE_STOPPED) ||
3347 QDIO_IRQ_STATE_ERR)),
3348 QDIO_ACTIVATE_TIMEOUT);
3350 switch (irq_ptr->state) {
3351 case QDIO_IRQ_STATE_STOPPED:
3352 case QDIO_IRQ_STATE_ERR:
3353 up(&irq_ptr->setting_up_sema);
3354 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
3355 down(&irq_ptr->setting_up_sema);
3359 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
3363 up(&irq_ptr->setting_up_sema);
3368 /* buffers filled forwards again to make Rick happy */
3370 qdio_do_qdio_fill_input(struct qdio_q *q, unsigned int qidx,
3371 unsigned int count, struct qdio_buffer *buffers)
3373 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
3374 qidx &= (QDIO_MAX_BUFFERS_PER_Q - 1);
3375 if (irq->is_qebsm) {
3377 set_slsb(q, &qidx, SLSB_CU_INPUT_EMPTY, &count);
3381 set_slsb(q, &qidx, SLSB_CU_INPUT_EMPTY, &count);
3384 qidx = (qidx + 1) & (QDIO_MAX_BUFFERS_PER_Q - 1);
3389 qdio_do_qdio_fill_output(struct qdio_q *q, unsigned int qidx,
3390 unsigned int count, struct qdio_buffer *buffers)
3392 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
3394 qidx &= (QDIO_MAX_BUFFERS_PER_Q - 1);
3395 if (irq->is_qebsm) {
3397 set_slsb(q, &qidx, SLSB_CU_OUTPUT_PRIMED, &count);
3402 set_slsb(q, &qidx, SLSB_CU_OUTPUT_PRIMED, &count);
3405 qidx = (qidx + 1) & (QDIO_MAX_BUFFERS_PER_Q - 1);
3410 do_qdio_handle_inbound(struct qdio_q *q, unsigned int callflags,
3411 unsigned int qidx, unsigned int count,
3412 struct qdio_buffer *buffers)
3416 /* This is the inbound handling of queues */
3417 used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count;
3419 qdio_do_qdio_fill_input(q,qidx,count,buffers);
3421 if ((used_elements+count==QDIO_MAX_BUFFERS_PER_Q)&&
3422 (callflags&QDIO_FLAG_UNDER_INTERRUPT))
3423 atomic_xchg(&q->polling,0);
3427 if (callflags&QDIO_FLAG_DONT_SIGA)
3432 result=qdio_siga_input(q);
3435 q->error_status_flags|=
3436 QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR;
3437 q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR;
3438 q->siga_error=result;
3446 do_qdio_handle_outbound(struct qdio_q *q, unsigned int callflags,
3447 unsigned int qidx, unsigned int count,
3448 struct qdio_buffer *buffers)
3451 unsigned int cnt, start_buf;
3452 unsigned char state = 0;
3453 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
3455 /* This is the outbound handling of queues */
3456 if (qdio_performance_stats)
3457 perf_stats.start_time_outbound=NOW;
3459 qdio_do_qdio_fill_output(q,qidx,count,buffers);
3461 used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count;
3463 if (callflags&QDIO_FLAG_DONT_SIGA) {
3464 if (qdio_performance_stats) {
3465 perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound;
3466 perf_stats.outbound_cnt++;
3470 if (q->is_iqdio_q) {
3471 /* one siga for every sbal */
3473 qdio_kick_outbound_q(q);
3475 __qdio_outbound_processing(q);
3477 /* under VM, we do a SIGA sync unconditionally */
3481 * w/o shadow queues (else branch of
3482 * SYNC_MEMORY :-/ ), we try to
3483 * fast-requeue buffers
3485 if (irq->is_qebsm) {
3487 start_buf = ((qidx+QDIO_MAX_BUFFERS_PER_Q-1) &
3488 (QDIO_MAX_BUFFERS_PER_Q-1));
3489 qdio_do_eqbs(q, &state, &start_buf, &cnt);
3491 state = q->slsb.acc.val[(qidx+QDIO_MAX_BUFFERS_PER_Q-1)
3492 &(QDIO_MAX_BUFFERS_PER_Q-1) ];
3493 if (state != SLSB_CU_OUTPUT_PRIMED) {
3494 qdio_kick_outbound_q(q);
3496 QDIO_DBF_TEXT3(0,trace, "fast-req");
3497 if (qdio_performance_stats)
3498 perf_stats.fast_reqs++;
3502 * only marking the q could take too long,
3503 * the upper layer module could do a lot of
3504 * traffic in that time
3506 __qdio_outbound_processing(q);
3509 if (qdio_performance_stats) {
3510 perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound;
3511 perf_stats.outbound_cnt++;
3515 /* count must be 1 in iqdio */
3517 do_QDIO(struct ccw_device *cdev,unsigned int callflags,
3518 unsigned int queue_number, unsigned int qidx,
3519 unsigned int count,struct qdio_buffer *buffers)
3521 struct qdio_irq *irq_ptr;
3522 #ifdef CONFIG_QDIO_DEBUG
3525 sprintf(dbf_text,"doQD%04x",cdev->private->schid.sch_no);
3526 QDIO_DBF_TEXT3(0,trace,dbf_text);
3527 #endif /* CONFIG_QDIO_DEBUG */
3529 if ( (qidx>QDIO_MAX_BUFFERS_PER_Q) ||
3530 (count>QDIO_MAX_BUFFERS_PER_Q) ||
3531 (queue_number>QDIO_MAX_QUEUES_PER_IRQ) )
3537 irq_ptr = cdev->private->qdio_data;
3541 #ifdef CONFIG_QDIO_DEBUG
3542 if (callflags&QDIO_FLAG_SYNC_INPUT)
3543 QDIO_DBF_HEX3(0,trace,&irq_ptr->input_qs[queue_number],
3546 QDIO_DBF_HEX3(0,trace,&irq_ptr->output_qs[queue_number],
3548 sprintf(dbf_text,"flag%04x",callflags);
3549 QDIO_DBF_TEXT3(0,trace,dbf_text);
3550 sprintf(dbf_text,"qi%02xct%02x",qidx,count);
3551 QDIO_DBF_TEXT3(0,trace,dbf_text);
3552 #endif /* CONFIG_QDIO_DEBUG */
3554 if (irq_ptr->state!=QDIO_IRQ_STATE_ACTIVE)
3557 if (callflags&QDIO_FLAG_SYNC_INPUT)
3558 do_qdio_handle_inbound(irq_ptr->input_qs[queue_number],
3559 callflags, qidx, count, buffers);
3560 else if (callflags&QDIO_FLAG_SYNC_OUTPUT)
3561 do_qdio_handle_outbound(irq_ptr->output_qs[queue_number],
3562 callflags, qidx, count, buffers);
3564 QDIO_DBF_TEXT3(1,trace,"doQD:inv");
3571 qdio_perf_procfile_read(char *buffer, char **buffer_location, off_t offset,
3572 int buffer_length, int *eof, void *data)
3576 /* we are always called with buffer_length=4k, so we all
3577 deliver on the first read */
3581 #define _OUTP_IT(x...) c+=sprintf(buffer+c,x)
3582 _OUTP_IT("i_p_nc/c=%lu/%lu\n",i_p_nc,i_p_c);
3583 _OUTP_IT("ii_p_nc/c=%lu/%lu\n",ii_p_nc,ii_p_c);
3584 _OUTP_IT("o_p_nc/c=%lu/%lu\n",o_p_nc,o_p_c);
3585 _OUTP_IT("Number of tasklet runs (total) : %lu\n",
3586 perf_stats.tl_runs);
3588 _OUTP_IT("Number of SIGA sync's issued : %lu\n",
3589 perf_stats.siga_syncs);
3590 _OUTP_IT("Number of SIGA in's issued : %lu\n",
3591 perf_stats.siga_ins);
3592 _OUTP_IT("Number of SIGA out's issued : %lu\n",
3593 perf_stats.siga_outs);
3594 _OUTP_IT("Number of PCIs caught : %lu\n",
3596 _OUTP_IT("Number of adapter interrupts caught : %lu\n",
3597 perf_stats.thinints);
3598 _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %lu\n",
3599 perf_stats.fast_reqs);
3601 _OUTP_IT("Total time of all inbound actions (us) incl. UL : %lu\n",
3602 perf_stats.inbound_time);
3603 _OUTP_IT("Number of inbound transfers : %lu\n",
3604 perf_stats.inbound_cnt);
3605 _OUTP_IT("Total time of all outbound do_QDIOs (us) : %lu\n",
3606 perf_stats.outbound_time);
3607 _OUTP_IT("Number of do_QDIOs outbound : %lu\n",
3608 perf_stats.outbound_cnt);
3614 static struct proc_dir_entry *qdio_perf_proc_file;
3617 qdio_add_procfs_entry(void)
3619 proc_perf_file_registration=0;
3620 qdio_perf_proc_file=create_proc_entry(QDIO_PERF,
3621 S_IFREG|0444,&proc_root);
3622 if (qdio_perf_proc_file) {
3623 qdio_perf_proc_file->read_proc=&qdio_perf_procfile_read;
3624 } else proc_perf_file_registration=-1;
3626 if (proc_perf_file_registration)
3627 QDIO_PRINT_WARN("was not able to register perf. " \
3628 "proc-file (%i).\n",
3629 proc_perf_file_registration);
3633 qdio_remove_procfs_entry(void)
3635 perf_stats.tl_runs=0;
3637 if (!proc_perf_file_registration) /* means if it went ok earlier */
3638 remove_proc_entry(QDIO_PERF,&proc_root);
3642 * attributes in sysfs
3643 *****************************************************************************/
3646 qdio_performance_stats_show(struct bus_type *bus, char *buf)
3648 return sprintf(buf, "%i\n", qdio_performance_stats ? 1 : 0);
3652 qdio_performance_stats_store(struct bus_type *bus, const char *buf, size_t count)
3657 i = simple_strtoul(buf, &tmp, 16);
3658 if ((i == 0) || (i == 1)) {
3659 if (i == qdio_performance_stats)
3661 qdio_performance_stats = i;
3663 /* reset perf. stat. info */
3670 memset(&perf_stats, 0, sizeof(struct qdio_perf_stats));
3673 QDIO_PRINT_WARN("QDIO performance_stats: write 0 or 1 to this file!\n");
3679 static BUS_ATTR(qdio_performance_stats, 0644, qdio_performance_stats_show,
3680 qdio_performance_stats_store);
3683 tiqdio_register_thinints(void)
3686 register_thinint_result=
3687 s390_register_adapter_interrupt(&tiqdio_thinint_handler);
3688 if (register_thinint_result) {
3689 sprintf(dbf_text,"regthn%x",(register_thinint_result&0xff));
3690 QDIO_DBF_TEXT0(0,setup,dbf_text);
3691 QDIO_PRINT_ERR("failed to register adapter handler " \
3692 "(rc=%i).\nAdapter interrupts might " \
3693 "not work. Continuing.\n",
3694 register_thinint_result);
3699 tiqdio_unregister_thinints(void)
3701 if (!register_thinint_result)
3702 s390_unregister_adapter_interrupt(&tiqdio_thinint_handler);
3706 qdio_get_qdio_memory(void)
3709 indicator_used[0]=1;
3711 for (i=1;i<INDICATORS_PER_CACHELINE;i++)
3712 indicator_used[i]=0;
3713 indicators = kzalloc(sizeof(__u32)*(INDICATORS_PER_CACHELINE),
3721 qdio_release_qdio_memory(void)
3728 qdio_unregister_dbf_views(void)
3731 debug_unregister(qdio_dbf_setup);
3733 debug_unregister(qdio_dbf_sbal);
3735 debug_unregister(qdio_dbf_sense);
3737 debug_unregister(qdio_dbf_trace);
3738 #ifdef CONFIG_QDIO_DEBUG
3739 if (qdio_dbf_slsb_out)
3740 debug_unregister(qdio_dbf_slsb_out);
3741 if (qdio_dbf_slsb_in)
3742 debug_unregister(qdio_dbf_slsb_in);
3743 #endif /* CONFIG_QDIO_DEBUG */
3747 qdio_register_dbf_views(void)
3749 qdio_dbf_setup=debug_register(QDIO_DBF_SETUP_NAME,
3750 QDIO_DBF_SETUP_PAGES,
3751 QDIO_DBF_SETUP_NR_AREAS,
3752 QDIO_DBF_SETUP_LEN);
3753 if (!qdio_dbf_setup)
3755 debug_register_view(qdio_dbf_setup,&debug_hex_ascii_view);
3756 debug_set_level(qdio_dbf_setup,QDIO_DBF_SETUP_LEVEL);
3758 qdio_dbf_sbal=debug_register(QDIO_DBF_SBAL_NAME,
3759 QDIO_DBF_SBAL_PAGES,
3760 QDIO_DBF_SBAL_NR_AREAS,
3765 debug_register_view(qdio_dbf_sbal,&debug_hex_ascii_view);
3766 debug_set_level(qdio_dbf_sbal,QDIO_DBF_SBAL_LEVEL);
3768 qdio_dbf_sense=debug_register(QDIO_DBF_SENSE_NAME,
3769 QDIO_DBF_SENSE_PAGES,
3770 QDIO_DBF_SENSE_NR_AREAS,
3771 QDIO_DBF_SENSE_LEN);
3772 if (!qdio_dbf_sense)
3775 debug_register_view(qdio_dbf_sense,&debug_hex_ascii_view);
3776 debug_set_level(qdio_dbf_sense,QDIO_DBF_SENSE_LEVEL);
3778 qdio_dbf_trace=debug_register(QDIO_DBF_TRACE_NAME,
3779 QDIO_DBF_TRACE_PAGES,
3780 QDIO_DBF_TRACE_NR_AREAS,
3781 QDIO_DBF_TRACE_LEN);
3782 if (!qdio_dbf_trace)
3785 debug_register_view(qdio_dbf_trace,&debug_hex_ascii_view);
3786 debug_set_level(qdio_dbf_trace,QDIO_DBF_TRACE_LEVEL);
3788 #ifdef CONFIG_QDIO_DEBUG
3789 qdio_dbf_slsb_out=debug_register(QDIO_DBF_SLSB_OUT_NAME,
3790 QDIO_DBF_SLSB_OUT_PAGES,
3791 QDIO_DBF_SLSB_OUT_NR_AREAS,
3792 QDIO_DBF_SLSB_OUT_LEN);
3793 if (!qdio_dbf_slsb_out)
3795 debug_register_view(qdio_dbf_slsb_out,&debug_hex_ascii_view);
3796 debug_set_level(qdio_dbf_slsb_out,QDIO_DBF_SLSB_OUT_LEVEL);
3798 qdio_dbf_slsb_in=debug_register(QDIO_DBF_SLSB_IN_NAME,
3799 QDIO_DBF_SLSB_IN_PAGES,
3800 QDIO_DBF_SLSB_IN_NR_AREAS,
3801 QDIO_DBF_SLSB_IN_LEN);
3802 if (!qdio_dbf_slsb_in)
3804 debug_register_view(qdio_dbf_slsb_in,&debug_hex_ascii_view);
3805 debug_set_level(qdio_dbf_slsb_in,QDIO_DBF_SLSB_IN_LEVEL);
3806 #endif /* CONFIG_QDIO_DEBUG */
3809 QDIO_PRINT_ERR("not enough memory for dbf.\n");
3810 qdio_unregister_dbf_views();
3814 static void *qdio_mempool_alloc(gfp_t gfp_mask, void *size)
3816 return (void *) get_zeroed_page(gfp_mask|GFP_DMA);
3819 static void qdio_mempool_free(void *element, void *size)
3821 free_page((unsigned long) element);
3830 printk("qdio: loading %s\n",version);
3832 res=qdio_get_qdio_memory();
3836 res = qdio_register_dbf_views();
3840 QDIO_DBF_TEXT0(0,setup,"initQDIO");
3841 res = bus_create_file(&ccw_bus_type, &bus_attr_qdio_performance_stats);
3843 memset((void*)&perf_stats,0,sizeof(perf_stats));
3844 QDIO_DBF_TEXT0(0,setup,"perfstat");
3846 QDIO_DBF_HEX0(0,setup,&ptr,sizeof(void*));
3848 qdio_add_procfs_entry();
3850 qdio_mempool_scssc = mempool_create(QDIO_MEMPOOL_SCSSC_ELEMENTS,
3852 qdio_mempool_free, NULL);
3854 if (tiqdio_check_chsc_availability())
3855 QDIO_PRINT_ERR("Not all CHSCs supported. Continuing.\n");
3857 tiqdio_register_thinints();
3865 tiqdio_unregister_thinints();
3866 qdio_remove_procfs_entry();
3867 qdio_release_qdio_memory();
3868 qdio_unregister_dbf_views();
3869 mempool_destroy(qdio_mempool_scssc);
3870 bus_remove_file(&ccw_bus_type, &bus_attr_qdio_performance_stats);
3871 printk("qdio: %s: module removed\n",version);
3874 module_init(init_QDIO);
3875 module_exit(cleanup_QDIO);
3877 EXPORT_SYMBOL(qdio_allocate);
3878 EXPORT_SYMBOL(qdio_establish);
3879 EXPORT_SYMBOL(qdio_initialize);
3880 EXPORT_SYMBOL(qdio_activate);
3881 EXPORT_SYMBOL(do_QDIO);
3882 EXPORT_SYMBOL(qdio_shutdown);
3883 EXPORT_SYMBOL(qdio_free);
3884 EXPORT_SYMBOL(qdio_cleanup);
3885 EXPORT_SYMBOL(qdio_synchronize);