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>
35 #include <linux/delay.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>
41 #include <linux/semaphore.h>
43 #include <asm/ccwdev.h>
45 #include <asm/atomic.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 struct qdio_perf_stats perf_stats;
74 static int hydra_thinints;
75 static int is_passthrough = 0;
78 static int indicator_used[INDICATORS_PER_CACHELINE];
79 static __u32 * volatile indicators;
80 static __u32 volatile spare_indicator;
81 static atomic_t spare_indicator_usecount;
82 #define QDIO_MEMPOOL_SCSSC_ELEMENTS 2
83 static mempool_t *qdio_mempool_scssc;
84 static struct kmem_cache *qdio_q_cache;
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 void *tiqdio_ind;
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 **********************/
115 static inline void qdio_perf_stat_inc(atomic64_t *count)
117 if (qdio_performance_stats)
121 static inline void qdio_perf_stat_dec(atomic64_t *count)
123 if (qdio_performance_stats)
126 #else /* CONFIG_64BIT */
127 static inline void qdio_perf_stat_inc(atomic_t *count)
129 if (qdio_performance_stats)
133 static inline void qdio_perf_stat_dec(atomic_t *count)
135 if (qdio_performance_stats)
138 #endif /* CONFIG_64BIT */
141 qdio_get_micros(void)
143 return (get_clock() >> 12); /* time>>12 is microseconds */
147 * unfortunately, we can't just xchg the values; in do_QDIO we want to reserve
148 * the q in any case, so that we'll not be interrupted when we are in
149 * qdio_mark_tiq... shouldn't have a really bad impact, as reserving almost
150 * ever works (last famous words)
153 qdio_reserve_q(struct qdio_q *q)
155 return atomic_add_return(1,&q->use_count) - 1;
159 qdio_release_q(struct qdio_q *q)
161 atomic_dec(&q->use_count);
166 qdio_check_ccq(struct qdio_q *q, unsigned int ccq)
170 if (ccq == 0 || ccq == 32)
172 if (ccq == 96 || ccq == 97)
174 /*notify devices immediately*/
175 sprintf(dbf_text,"%d", ccq);
176 QDIO_DBF_TEXT2(1,trace,dbf_text);
179 /* EQBS: extract buffer states */
181 qdio_do_eqbs(struct qdio_q *q, unsigned char *state,
182 unsigned int *start, unsigned int *cnt)
184 struct qdio_irq *irq;
185 unsigned int tmp_cnt, q_no, ccq;
191 irq = (struct qdio_irq*)q->irq_ptr;
194 q_no += irq->no_input_qs;
196 ccq = do_eqbs(irq->sch_token, state, q_no, start, cnt);
197 rc = qdio_check_ccq(q, ccq);
198 if ((ccq == 96) && (tmp_cnt != *cnt))
201 QDIO_DBF_TEXT5(1,trace,"eqAGAIN");
205 QDIO_DBF_TEXT2(1,trace,"eqberr");
206 sprintf(dbf_text,"%2x,%2x,%d,%d",tmp_cnt, *cnt, ccq, q_no);
207 QDIO_DBF_TEXT2(1,trace,dbf_text);
208 q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION|
209 QDIO_STATUS_LOOK_FOR_ERROR,
210 0, 0, 0, -1, -1, q->int_parm);
213 return (tmp_cnt - *cnt);
216 /* SQBS: set buffer states */
218 qdio_do_sqbs(struct qdio_q *q, unsigned char state,
219 unsigned int *start, unsigned int *cnt)
221 struct qdio_irq *irq;
222 unsigned int tmp_cnt, q_no, ccq;
228 irq = (struct qdio_irq*)q->irq_ptr;
231 q_no += irq->no_input_qs;
233 ccq = do_sqbs(irq->sch_token, state, q_no, start, cnt);
234 rc = qdio_check_ccq(q, ccq);
236 QDIO_DBF_TEXT5(1,trace,"sqAGAIN");
240 QDIO_DBF_TEXT3(1,trace,"sqberr");
241 sprintf(dbf_text,"%2x,%2x",tmp_cnt,*cnt);
242 QDIO_DBF_TEXT3(1,trace,dbf_text);
243 sprintf(dbf_text,"%d,%d",ccq,q_no);
244 QDIO_DBF_TEXT3(1,trace,dbf_text);
245 q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION|
246 QDIO_STATUS_LOOK_FOR_ERROR,
247 0, 0, 0, -1, -1, q->int_parm);
250 return (tmp_cnt - *cnt);
254 qdio_set_slsb(struct qdio_q *q, unsigned int *bufno,
255 unsigned char state, unsigned int *count)
258 struct qdio_irq *irq;
260 irq = (struct qdio_irq*)q->irq_ptr;
261 if (!irq->is_qebsm) {
262 slsb = (char *)&q->slsb.acc.val[(*bufno)];
266 return qdio_do_sqbs(q, state, bufno, count);
269 #ifdef CONFIG_QDIO_DEBUG
271 qdio_trace_slsb(struct qdio_q *q)
273 if (q->queue_type==QDIO_TRACE_QTYPE) {
275 QDIO_DBF_HEX2(0,slsb_in,&q->slsb,
276 QDIO_MAX_BUFFERS_PER_Q);
278 QDIO_DBF_HEX2(0,slsb_out,&q->slsb,
279 QDIO_MAX_BUFFERS_PER_Q);
285 set_slsb(struct qdio_q *q, unsigned int *bufno,
286 unsigned char state, unsigned int *count)
289 #ifdef CONFIG_QDIO_DEBUG
292 rc = qdio_set_slsb(q, bufno, state, count);
293 #ifdef CONFIG_QDIO_DEBUG
299 qdio_siga_sync(struct qdio_q *q, unsigned int gpr2,
304 QDIO_DBF_TEXT4(0,trace,"sigasync");
305 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
307 qdio_perf_stat_inc(&perf_stats.siga_syncs);
309 cc = do_siga_sync(q->schid, gpr2, gpr3);
311 QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*));
317 qdio_siga_sync_q(struct qdio_q *q)
320 return qdio_siga_sync(q, 0, q->mask);
321 return qdio_siga_sync(q, q->mask, 0);
325 __do_siga_output(struct qdio_q *q, unsigned int *busy_bit)
327 struct qdio_irq *irq;
331 irq = (struct qdio_irq *) q->irq_ptr;
333 schid = *((u32 *)&q->schid);
335 schid = irq->sch_token;
338 return do_siga_output(schid, q->mask, busy_bit, fc);
342 * returns QDIO_SIGA_ERROR_ACCESS_EXCEPTION as cc, when SIGA returns
343 * an access exception
346 qdio_siga_output(struct qdio_q *q)
352 qdio_perf_stat_inc(&perf_stats.siga_outs);
354 QDIO_DBF_TEXT4(0,trace,"sigaout");
355 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
358 cc = __do_siga_output(q, &busy_bit);
359 //QDIO_PRINT_ERR("cc=%x, busy=%x\n",cc,busy_bit);
360 if ((cc==2) && (busy_bit) && (q->is_iqdio_q)) {
363 if ((NOW-start_time)>QDIO_BUSY_BIT_PATIENCE)
369 if ((cc==2) && (busy_bit))
370 cc |= QDIO_SIGA_ERROR_B_BIT_SET;
373 QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*));
379 qdio_siga_input(struct qdio_q *q)
383 QDIO_DBF_TEXT4(0,trace,"sigain");
384 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
386 qdio_perf_stat_inc(&perf_stats.siga_ins);
388 cc = do_siga_input(q->schid, q->mask);
391 QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*));
396 /* locked by the locks in qdio_activate and qdio_cleanup */
398 qdio_get_indicator(void)
402 for (i = 0; i < INDICATORS_PER_CACHELINE; i++)
403 if (!indicator_used[i]) {
407 atomic_inc(&spare_indicator_usecount);
408 return (__u32 * volatile) &spare_indicator;
411 /* locked by the locks in qdio_activate and qdio_cleanup */
413 qdio_put_indicator(__u32 *addr)
417 if ( (addr) && (addr!=&spare_indicator) ) {
421 if (addr == &spare_indicator)
422 atomic_dec(&spare_indicator_usecount);
426 tiqdio_clear_summary_bit(__u32 *location)
428 QDIO_DBF_TEXT5(0,trace,"clrsummb");
429 QDIO_DBF_HEX5(0,trace,&location,sizeof(void*));
435 tiqdio_set_summary_bit(__u32 *location)
437 QDIO_DBF_TEXT5(0,trace,"setsummb");
438 QDIO_DBF_HEX5(0,trace,&location,sizeof(void*));
444 tiqdio_sched_tl(void)
446 tasklet_hi_schedule(&tiqdio_tasklet);
450 qdio_mark_tiq(struct qdio_q *q)
454 QDIO_DBF_TEXT4(0,trace,"mark iq");
455 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
457 spin_lock_irqsave(&ttiq_list_lock,flags);
458 if (unlikely(atomic_read(&q->is_in_shutdown)))
464 if ((q->list_prev) || (q->list_next))
472 q->list_next=tiq_list;
473 q->list_prev=tiq_list->list_prev;
474 tiq_list->list_prev->list_next=q;
475 tiq_list->list_prev=q;
477 spin_unlock_irqrestore(&ttiq_list_lock,flags);
479 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
483 spin_unlock_irqrestore(&ttiq_list_lock,flags);
488 qdio_mark_q(struct qdio_q *q)
490 QDIO_DBF_TEXT4(0,trace,"mark q");
491 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
493 if (unlikely(atomic_read(&q->is_in_shutdown)))
496 tasklet_schedule(&q->tasklet);
500 qdio_stop_polling(struct qdio_q *q)
502 #ifdef QDIO_USE_PROCESSING_STATE
503 unsigned int tmp, gsf, count = 1;
504 unsigned char state = 0;
505 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
507 if (!atomic_xchg(&q->polling,0))
510 QDIO_DBF_TEXT4(0,trace,"stoppoll");
511 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
513 /* show the card that we are not polling anymore */
517 tmp = gsf = GET_SAVED_FRONTIER(q);
518 tmp = ((tmp + QDIO_MAX_BUFFERS_PER_Q-1) & (QDIO_MAX_BUFFERS_PER_Q-1) );
519 set_slsb(q, &tmp, SLSB_P_INPUT_NOT_INIT, &count);
522 * we don't issue this SYNC_MEMORY, as we trust Rick T and
523 * moreover will not use the PROCESSING state under VM, so
524 * q->polling was 0 anyway
529 qdio_do_eqbs(q, &state, &gsf, &count);
531 state = q->slsb.acc.val[gsf];
532 if (state != SLSB_P_INPUT_PRIMED)
535 * set our summary bit again, as otherwise there is a
536 * small window we can miss between resetting it and
537 * checking for PRIMED state
540 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
543 #else /* QDIO_USE_PROCESSING_STATE */
545 #endif /* QDIO_USE_PROCESSING_STATE */
549 * see the comment in do_QDIO and before qdio_reserve_q about the
550 * sophisticated locking outside of unmark_q, so that we don't need to
551 * disable the interrupts :-)
554 qdio_unmark_q(struct qdio_q *q)
558 QDIO_DBF_TEXT4(0,trace,"unmark q");
559 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
561 if ((!q->list_prev)||(!q->list_next))
564 if ((q->is_thinint_q)&&(q->is_input_q)) {
566 spin_lock_irqsave(&ttiq_list_lock,flags);
567 /* in case cleanup has done this already and simultanously
568 * qdio_unmark_q is called from the interrupt handler, we've
569 * got to check this in this specific case again */
570 if ((!q->list_prev)||(!q->list_next))
572 if (q->list_next==q) {
573 /* q was the only interesting q */
578 q->list_next->list_prev=q->list_prev;
579 q->list_prev->list_next=q->list_next;
580 tiq_list=q->list_next;
585 spin_unlock_irqrestore(&ttiq_list_lock,flags);
589 static inline unsigned long
590 tiqdio_clear_global_summary(void)
594 QDIO_DBF_TEXT5(0,trace,"clrglobl");
596 time = do_clear_global_summary();
598 QDIO_DBF_HEX5(0,trace,&time,sizeof(unsigned long));
604 /************************* OUTBOUND ROUTINES *******************************/
606 qdio_qebsm_get_outbound_buffer_frontier(struct qdio_q *q)
608 struct qdio_irq *irq;
610 unsigned int cnt, count, ftc;
612 irq = (struct qdio_irq *) q->irq_ptr;
613 if ((!q->is_iqdio_q) && (!q->hydra_gives_outbound_pcis))
616 ftc = q->first_to_check;
617 count = qdio_min(atomic_read(&q->number_of_buffers_used),
618 (QDIO_MAX_BUFFERS_PER_Q-1));
620 return q->first_to_check;
621 cnt = qdio_do_eqbs(q, &state, &ftc, &count);
623 return q->first_to_check;
625 case SLSB_P_OUTPUT_ERROR:
626 QDIO_DBF_TEXT3(0,trace,"outperr");
627 atomic_sub(cnt , &q->number_of_buffers_used);
629 q->error_status_flags |=
630 QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR;
631 q->qdio_error = SLSB_P_OUTPUT_ERROR;
632 q->error_status_flags |= QDIO_STATUS_LOOK_FOR_ERROR;
633 q->first_to_check = ftc;
635 case SLSB_P_OUTPUT_EMPTY:
636 QDIO_DBF_TEXT5(0,trace,"outpempt");
637 atomic_sub(cnt, &q->number_of_buffers_used);
638 q->first_to_check = ftc;
640 case SLSB_CU_OUTPUT_PRIMED:
641 /* all buffers primed */
642 QDIO_DBF_TEXT5(0,trace,"outpprim");
647 QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int));
648 return q->first_to_check;
652 qdio_qebsm_get_inbound_buffer_frontier(struct qdio_q *q)
654 struct qdio_irq *irq;
656 int tmp, ftc, count, cnt;
660 irq = (struct qdio_irq *) q->irq_ptr;
661 ftc = q->first_to_check;
662 count = qdio_min(atomic_read(&q->number_of_buffers_used),
663 (QDIO_MAX_BUFFERS_PER_Q-1));
665 return q->first_to_check;
666 cnt = qdio_do_eqbs(q, &state, &ftc, &count);
668 return q->first_to_check;
670 case SLSB_P_INPUT_ERROR :
671 #ifdef CONFIG_QDIO_DEBUG
672 QDIO_DBF_TEXT3(1,trace,"inperr");
673 sprintf(dbf_text,"%2x,%2x",ftc,count);
674 QDIO_DBF_TEXT3(1,trace,dbf_text);
675 #endif /* CONFIG_QDIO_DEBUG */
677 q->error_status_flags |=
678 QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR;
679 q->qdio_error = SLSB_P_INPUT_ERROR;
680 q->error_status_flags |= QDIO_STATUS_LOOK_FOR_ERROR;
681 atomic_sub(cnt, &q->number_of_buffers_used);
682 q->first_to_check = ftc;
684 case SLSB_P_INPUT_PRIMED :
685 QDIO_DBF_TEXT3(0,trace,"inptprim");
686 sprintf(dbf_text,"%2x,%2x",ftc,count);
687 QDIO_DBF_TEXT3(1,trace,dbf_text);
689 ftc = q->first_to_check;
690 #ifdef QDIO_USE_PROCESSING_STATE
693 tmp = set_slsb(q, &ftc, SLSB_P_INPUT_NOT_INIT, &cnt);
698 tmp += set_slsb(q, &ftc,
699 SLSB_P_INPUT_PROCESSING, &cnt);
700 atomic_set(&q->polling, 1);
702 tmp = set_slsb(q, &ftc, SLSB_P_INPUT_NOT_INIT, &cnt);
704 atomic_sub(tmp, &q->number_of_buffers_used);
705 q->first_to_check = ftc;
707 case SLSB_CU_INPUT_EMPTY:
708 case SLSB_P_INPUT_NOT_INIT:
709 case SLSB_P_INPUT_PROCESSING:
710 QDIO_DBF_TEXT5(0,trace,"inpnipro");
715 QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int));
716 return q->first_to_check;
720 qdio_get_outbound_buffer_frontier(struct qdio_q *q)
722 struct qdio_irq *irq;
724 unsigned int count = 1;
725 int first_not_to_check, f, f_mod_no;
728 QDIO_DBF_TEXT4(0,trace,"getobfro");
729 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
731 irq = (struct qdio_irq *) q->irq_ptr;
733 return qdio_qebsm_get_outbound_buffer_frontier(q);
735 slsb=&q->slsb.acc.val[0];
736 f_mod_no=f=q->first_to_check;
738 * f points to already processed elements, so f+no_used is correct...
739 * ... but: we don't check 128 buffers, as otherwise
740 * qdio_has_outbound_q_moved would return 0
742 first_not_to_check=f+qdio_min(atomic_read(&q->number_of_buffers_used),
743 (QDIO_MAX_BUFFERS_PER_Q-1));
745 if (((!q->is_iqdio_q) && (!q->hydra_gives_outbound_pcis)) ||
746 (q->queue_type == QDIO_IQDIO_QFMT_ASYNCH))
750 if (f==first_not_to_check)
753 switch(slsb[f_mod_no]) {
755 /* the adapter has not fetched the output yet */
756 case SLSB_CU_OUTPUT_PRIMED:
757 QDIO_DBF_TEXT5(0,trace,"outpprim");
760 /* the adapter got it */
761 case SLSB_P_OUTPUT_EMPTY:
762 atomic_dec(&q->number_of_buffers_used);
764 f_mod_no=f&(QDIO_MAX_BUFFERS_PER_Q-1);
765 QDIO_DBF_TEXT5(0,trace,"outpempt");
768 case SLSB_P_OUTPUT_ERROR:
769 QDIO_DBF_TEXT3(0,trace,"outperr");
770 sprintf(dbf_text,"%x-%x-%x",f_mod_no,
771 q->sbal[f_mod_no]->element[14].sbalf.value,
772 q->sbal[f_mod_no]->element[15].sbalf.value);
773 QDIO_DBF_TEXT3(1,trace,dbf_text);
774 QDIO_DBF_HEX2(1,sbal,q->sbal[f_mod_no],256);
776 /* kind of process the buffer */
777 set_slsb(q, &f_mod_no, SLSB_P_OUTPUT_NOT_INIT, &count);
780 * we increment the frontier, as this buffer
781 * was processed obviously
783 atomic_dec(&q->number_of_buffers_used);
784 f_mod_no=(f_mod_no+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
787 q->error_status_flags|=
788 QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR;
789 q->qdio_error=SLSB_P_OUTPUT_ERROR;
790 q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR;
796 QDIO_DBF_TEXT5(0,trace,"outpni");
799 return (q->first_to_check=f_mod_no);
802 /* all buffers are processed */
804 qdio_is_outbound_q_done(struct qdio_q *q)
807 #ifdef CONFIG_QDIO_DEBUG
811 no_used=atomic_read(&q->number_of_buffers_used);
813 #ifdef CONFIG_QDIO_DEBUG
815 sprintf(dbf_text,"oqisnt%02x",no_used);
816 QDIO_DBF_TEXT4(0,trace,dbf_text);
818 QDIO_DBF_TEXT4(0,trace,"oqisdone");
820 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
821 #endif /* CONFIG_QDIO_DEBUG */
826 qdio_has_outbound_q_moved(struct qdio_q *q)
830 i=qdio_get_outbound_buffer_frontier(q);
832 if ( (i!=GET_SAVED_FRONTIER(q)) ||
833 (q->error_status_flags&QDIO_STATUS_LOOK_FOR_ERROR) ) {
835 QDIO_DBF_TEXT4(0,trace,"oqhasmvd");
836 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
839 QDIO_DBF_TEXT4(0,trace,"oqhsntmv");
840 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
846 qdio_kick_outbound_q(struct qdio_q *q)
849 #ifdef CONFIG_QDIO_DEBUG
852 QDIO_DBF_TEXT4(0,trace,"kickoutq");
853 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
854 #endif /* CONFIG_QDIO_DEBUG */
859 /* here's the story with cc=2 and busy bit set (thanks, Rick):
860 * VM's CP could present us cc=2 and busy bit set on SIGA-write
861 * during reconfiguration of their Guest LAN (only in HIPERS mode,
862 * QDIO mode is asynchronous -- cc=2 and busy bit there will take
863 * the queues down immediately; and not being under VM we have a
864 * problem on cc=2 and busy bit set right away).
866 * Therefore qdio_siga_output will try for a short time constantly,
867 * if such a condition occurs. If it doesn't change, it will
868 * increase the busy_siga_counter and save the timestamp, and
869 * schedule the queue for later processing (via mark_q, using the
870 * queue tasklet). __qdio_outbound_processing will check out the
871 * counter. If non-zero, it will call qdio_kick_outbound_q as often
872 * as the value of the counter. This will attempt further SIGA
873 * instructions. For each successful SIGA, the counter is
874 * decreased, for failing SIGAs the counter remains the same, after
876 * After some time of no movement, qdio_kick_outbound_q will
877 * finally fail and reflect corresponding error codes to call
878 * the upper layer module and have it take the queues down.
880 * Note that this is a change from the original HiperSockets design
881 * (saying cc=2 and busy bit means take the queues down), but in
882 * these days Guest LAN didn't exist... excessive cc=2 with busy bit
883 * conditions will still take the queues down, but the threshold is
884 * higher due to the Guest LAN environment.
888 result=qdio_siga_output(q);
892 /* went smooth this time, reset timestamp */
893 #ifdef CONFIG_QDIO_DEBUG
894 QDIO_DBF_TEXT3(0,trace,"cc2reslv");
895 sprintf(dbf_text,"%4x%2x%2x",q->schid.sch_no,q->q_no,
896 atomic_read(&q->busy_siga_counter));
897 QDIO_DBF_TEXT3(0,trace,dbf_text);
898 #endif /* CONFIG_QDIO_DEBUG */
899 q->timing.busy_start=0;
901 case (2|QDIO_SIGA_ERROR_B_BIT_SET):
902 /* cc=2 and busy bit: */
903 atomic_inc(&q->busy_siga_counter);
905 /* if the last siga was successful, save
907 if (!q->timing.busy_start)
908 q->timing.busy_start=NOW;
910 /* if we're in time, don't touch error_status_flags
912 if (NOW-q->timing.busy_start<QDIO_BUSY_BIT_GIVE_UP) {
916 QDIO_DBF_TEXT2(0,trace,"cc2REPRT");
917 #ifdef CONFIG_QDIO_DEBUG
918 sprintf(dbf_text,"%4x%2x%2x",q->schid.sch_no,q->q_no,
919 atomic_read(&q->busy_siga_counter));
920 QDIO_DBF_TEXT3(0,trace,dbf_text);
921 #endif /* CONFIG_QDIO_DEBUG */
922 /* else fallthrough and report error */
924 /* for plain cc=1, 2 or 3: */
926 q->error_status_flags|=
927 QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR;
928 q->error_status_flags|=
929 QDIO_STATUS_LOOK_FOR_ERROR;
930 q->siga_error=result;
935 qdio_kick_outbound_handler(struct qdio_q *q)
937 int start, end, real_end, count;
938 #ifdef CONFIG_QDIO_DEBUG
942 start = q->first_element_to_kick;
943 /* last_move_ftc was just updated */
944 real_end = GET_SAVED_FRONTIER(q);
945 end = (real_end+QDIO_MAX_BUFFERS_PER_Q-1)&
946 (QDIO_MAX_BUFFERS_PER_Q-1);
947 count = (end+QDIO_MAX_BUFFERS_PER_Q+1-start)&
948 (QDIO_MAX_BUFFERS_PER_Q-1);
950 #ifdef CONFIG_QDIO_DEBUG
951 QDIO_DBF_TEXT4(0,trace,"kickouth");
952 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
954 sprintf(dbf_text,"s=%2xc=%2x",start,count);
955 QDIO_DBF_TEXT4(0,trace,dbf_text);
956 #endif /* CONFIG_QDIO_DEBUG */
958 if (q->state==QDIO_IRQ_STATE_ACTIVE)
959 q->handler(q->cdev,QDIO_STATUS_OUTBOUND_INT|
960 q->error_status_flags,
961 q->qdio_error,q->siga_error,q->q_no,start,count,
964 /* for the next time: */
965 q->first_element_to_kick=real_end;
968 q->error_status_flags=0;
972 __qdio_outbound_processing(struct qdio_q *q)
976 QDIO_DBF_TEXT4(0,trace,"qoutproc");
977 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
979 if (unlikely(qdio_reserve_q(q))) {
981 qdio_perf_stat_inc(&perf_stats.outbound_tl_runs_resched);
982 /* as we're sissies, we'll check next time */
983 if (likely(!atomic_read(&q->is_in_shutdown))) {
985 QDIO_DBF_TEXT4(0,trace,"busy,agn");
989 qdio_perf_stat_inc(&perf_stats.outbound_tl_runs);
990 qdio_perf_stat_inc(&perf_stats.tl_runs);
992 /* see comment in qdio_kick_outbound_q */
993 siga_attempts=atomic_read(&q->busy_siga_counter);
994 while (siga_attempts) {
995 atomic_dec(&q->busy_siga_counter);
996 qdio_kick_outbound_q(q);
1000 if (qdio_has_outbound_q_moved(q))
1001 qdio_kick_outbound_handler(q);
1003 if (q->queue_type == QDIO_ZFCP_QFMT) {
1004 if ((!q->hydra_gives_outbound_pcis) &&
1005 (!qdio_is_outbound_q_done(q)))
1008 else if (((!q->is_iqdio_q) && (!q->is_pci_out)) ||
1009 (q->queue_type == QDIO_IQDIO_QFMT_ASYNCH)) {
1011 * make sure buffer switch from PRIMED to EMPTY is noticed
1012 * and outbound_handler is called
1014 if (qdio_is_outbound_q_done(q)) {
1015 del_timer(&q->timer);
1017 if (!timer_pending(&q->timer))
1018 mod_timer(&q->timer, jiffies +
1019 QDIO_FORCE_CHECK_TIMEOUT);
1027 qdio_outbound_processing(unsigned long q)
1029 __qdio_outbound_processing((struct qdio_q *) q);
1032 /************************* INBOUND ROUTINES *******************************/
1036 qdio_get_inbound_buffer_frontier(struct qdio_q *q)
1038 struct qdio_irq *irq;
1040 volatile char *slsb;
1041 unsigned int count = 1;
1042 int first_not_to_check;
1043 #ifdef CONFIG_QDIO_DEBUG
1045 #endif /* CONFIG_QDIO_DEBUG */
1046 #ifdef QDIO_USE_PROCESSING_STATE
1047 int last_position=-1;
1048 #endif /* QDIO_USE_PROCESSING_STATE */
1050 QDIO_DBF_TEXT4(0,trace,"getibfro");
1051 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1053 irq = (struct qdio_irq *) q->irq_ptr;
1055 return qdio_qebsm_get_inbound_buffer_frontier(q);
1057 slsb=&q->slsb.acc.val[0];
1058 f_mod_no=f=q->first_to_check;
1060 * we don't check 128 buffers, as otherwise qdio_has_inbound_q_moved
1063 first_not_to_check=f+qdio_min(atomic_read(&q->number_of_buffers_used),
1064 (QDIO_MAX_BUFFERS_PER_Q-1));
1067 * we don't use this one, as a PCI or we after a thin interrupt
1068 * will sync the queues
1073 f_mod_no=f&(QDIO_MAX_BUFFERS_PER_Q-1);
1074 if (f==first_not_to_check)
1076 switch (slsb[f_mod_no]) {
1078 /* CU_EMPTY means frontier is reached */
1079 case SLSB_CU_INPUT_EMPTY:
1080 QDIO_DBF_TEXT5(0,trace,"inptempt");
1083 /* P_PRIMED means set slsb to P_PROCESSING and move on */
1084 case SLSB_P_INPUT_PRIMED:
1085 QDIO_DBF_TEXT5(0,trace,"inptprim");
1087 #ifdef QDIO_USE_PROCESSING_STATE
1089 * as soon as running under VM, polling the input queues will
1090 * kill VM in terms of CP overhead
1093 set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count);
1095 /* set the previous buffer to NOT_INIT. The current
1096 * buffer will be set to PROCESSING at the end of
1097 * this function to avoid further interrupts. */
1098 if (last_position>=0)
1099 set_slsb(q, &last_position,
1100 SLSB_P_INPUT_NOT_INIT, &count);
1101 atomic_set(&q->polling,1);
1102 last_position=f_mod_no;
1104 #else /* QDIO_USE_PROCESSING_STATE */
1105 set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count);
1106 #endif /* QDIO_USE_PROCESSING_STATE */
1108 * not needed, as the inbound queue will be synced on the next
1109 * siga-r, resp. tiqdio_is_inbound_q_done will do the siga-s
1113 atomic_dec(&q->number_of_buffers_used);
1116 case SLSB_P_INPUT_NOT_INIT:
1117 case SLSB_P_INPUT_PROCESSING:
1118 QDIO_DBF_TEXT5(0,trace,"inpnipro");
1121 /* P_ERROR means frontier is reached, break and report error */
1122 case SLSB_P_INPUT_ERROR:
1123 #ifdef CONFIG_QDIO_DEBUG
1124 sprintf(dbf_text,"inperr%2x",f_mod_no);
1125 QDIO_DBF_TEXT3(1,trace,dbf_text);
1126 #endif /* CONFIG_QDIO_DEBUG */
1127 QDIO_DBF_HEX2(1,sbal,q->sbal[f_mod_no],256);
1129 /* kind of process the buffer */
1130 set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count);
1133 q->error_status_flags|=
1134 QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR;
1135 q->qdio_error=SLSB_P_INPUT_ERROR;
1136 q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR;
1138 /* we increment the frontier, as this buffer
1139 * was processed obviously */
1140 f_mod_no=(f_mod_no+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
1141 atomic_dec(&q->number_of_buffers_used);
1143 #ifdef QDIO_USE_PROCESSING_STATE
1145 #endif /* QDIO_USE_PROCESSING_STATE */
1149 /* everything else means frontier not changed (HALTED or so) */
1154 q->first_to_check=f_mod_no;
1156 #ifdef QDIO_USE_PROCESSING_STATE
1157 if (last_position>=0)
1158 set_slsb(q, &last_position, SLSB_P_INPUT_PROCESSING, &count);
1159 #endif /* QDIO_USE_PROCESSING_STATE */
1161 QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int));
1163 return q->first_to_check;
1167 qdio_has_inbound_q_moved(struct qdio_q *q)
1171 i=qdio_get_inbound_buffer_frontier(q);
1172 if ( (i!=GET_SAVED_FRONTIER(q)) ||
1173 (q->error_status_flags&QDIO_STATUS_LOOK_FOR_ERROR) ) {
1175 if ((!q->siga_sync)&&(!q->hydra_gives_outbound_pcis))
1178 QDIO_DBF_TEXT4(0,trace,"inhasmvd");
1179 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1182 QDIO_DBF_TEXT4(0,trace,"inhsntmv");
1183 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1188 /* means, no more buffers to be filled */
1190 tiqdio_is_inbound_q_done(struct qdio_q *q)
1193 unsigned int start_buf, count;
1194 unsigned char state = 0;
1195 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
1197 #ifdef CONFIG_QDIO_DEBUG
1201 no_used=atomic_read(&q->number_of_buffers_used);
1203 /* propagate the change from 82 to 80 through VM */
1206 #ifdef CONFIG_QDIO_DEBUG
1208 sprintf(dbf_text,"iqisnt%02x",no_used);
1209 QDIO_DBF_TEXT4(0,trace,dbf_text);
1211 QDIO_DBF_TEXT4(0,trace,"iniqisdo");
1213 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1214 #endif /* CONFIG_QDIO_DEBUG */
1218 if (irq->is_qebsm) {
1220 start_buf = q->first_to_check;
1221 qdio_do_eqbs(q, &state, &start_buf, &count);
1223 state = q->slsb.acc.val[q->first_to_check];
1224 if (state != SLSB_P_INPUT_PRIMED)
1226 * nothing more to do, if next buffer is not PRIMED.
1227 * note that we did a SYNC_MEMORY before, that there
1228 * has been a sychnronization.
1229 * we will return 0 below, as there is nothing to do
1230 * (stop_polling not necessary, as we have not been
1231 * using the PROCESSING state
1236 * ok, the next input buffer is primed. that means, that device state
1237 * change indicator and adapter local summary are set, so we will find
1239 * we will return 0 below, as there is nothing to do, except scheduling
1240 * ourselves for the next time.
1242 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1248 qdio_is_inbound_q_done(struct qdio_q *q)
1251 unsigned int start_buf, count;
1252 unsigned char state = 0;
1253 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
1255 #ifdef CONFIG_QDIO_DEBUG
1259 no_used=atomic_read(&q->number_of_buffers_used);
1262 * we need that one for synchronization with the adapter, as it
1263 * does a kind of PCI avoidance
1268 QDIO_DBF_TEXT4(0,trace,"inqisdnA");
1269 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1272 if (irq->is_qebsm) {
1274 start_buf = q->first_to_check;
1275 qdio_do_eqbs(q, &state, &start_buf, &count);
1277 state = q->slsb.acc.val[q->first_to_check];
1278 if (state == SLSB_P_INPUT_PRIMED) {
1279 /* we got something to do */
1280 QDIO_DBF_TEXT4(0,trace,"inqisntA");
1281 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1285 /* on VM, we don't poll, so the q is always done here */
1288 if (q->hydra_gives_outbound_pcis)
1292 * at this point we know, that inbound first_to_check
1293 * has (probably) not moved (see qdio_inbound_processing)
1295 if (NOW>GET_SAVED_TIMESTAMP(q)+q->timing.threshold) {
1296 #ifdef CONFIG_QDIO_DEBUG
1297 QDIO_DBF_TEXT4(0,trace,"inqisdon");
1298 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1299 sprintf(dbf_text,"pf%02xcn%02x",q->first_to_check,no_used);
1300 QDIO_DBF_TEXT4(0,trace,dbf_text);
1301 #endif /* CONFIG_QDIO_DEBUG */
1304 #ifdef CONFIG_QDIO_DEBUG
1305 QDIO_DBF_TEXT4(0,trace,"inqisntd");
1306 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1307 sprintf(dbf_text,"pf%02xcn%02x",q->first_to_check,no_used);
1308 QDIO_DBF_TEXT4(0,trace,dbf_text);
1309 #endif /* CONFIG_QDIO_DEBUG */
1315 qdio_kick_inbound_handler(struct qdio_q *q)
1317 int count, start, end, real_end, i;
1318 #ifdef CONFIG_QDIO_DEBUG
1322 QDIO_DBF_TEXT4(0,trace,"kickinh");
1323 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1325 start=q->first_element_to_kick;
1326 real_end=q->first_to_check;
1327 end=(real_end+QDIO_MAX_BUFFERS_PER_Q-1)&(QDIO_MAX_BUFFERS_PER_Q-1);
1335 i=(i+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
1338 #ifdef CONFIG_QDIO_DEBUG
1339 sprintf(dbf_text,"s=%2xc=%2x",start,count);
1340 QDIO_DBF_TEXT4(0,trace,dbf_text);
1341 #endif /* CONFIG_QDIO_DEBUG */
1343 if (likely(q->state==QDIO_IRQ_STATE_ACTIVE))
1345 QDIO_STATUS_INBOUND_INT|q->error_status_flags,
1346 q->qdio_error,q->siga_error,q->q_no,start,count,
1349 /* for the next time: */
1350 q->first_element_to_kick=real_end;
1353 q->error_status_flags=0;
1355 qdio_perf_stat_inc(&perf_stats.inbound_cnt);
1359 __tiqdio_inbound_processing(struct qdio_q *q, int spare_ind_was_set)
1361 struct qdio_irq *irq_ptr;
1365 QDIO_DBF_TEXT4(0,trace,"iqinproc");
1366 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1369 * we first want to reserve the q, so that we know, that we don't
1370 * interrupt ourselves and call qdio_unmark_q, as is_in_shutdown might
1373 if (unlikely(qdio_reserve_q(q))) {
1375 qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs_resched);
1377 * as we might just be about to stop polling, we make
1378 * sure that we check again at least once more
1383 qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs);
1384 if (unlikely(atomic_read(&q->is_in_shutdown))) {
1390 * we reset spare_ind_was_set, when the queue does not use the
1393 if (spare_ind_was_set)
1394 spare_ind_was_set = (q->dev_st_chg_ind == &spare_indicator);
1396 if (!(*(q->dev_st_chg_ind)) && !spare_ind_was_set)
1399 * q->dev_st_chg_ind is the indicator, be it shared or not.
1400 * only clear it, if indicator is non-shared
1402 if (q->dev_st_chg_ind != &spare_indicator)
1403 tiqdio_clear_summary_bit((__u32*)q->dev_st_chg_ind);
1405 if (q->hydra_gives_outbound_pcis) {
1406 if (!q->siga_sync_done_on_thinints) {
1408 } else if (!q->siga_sync_done_on_outb_tis) {
1409 SYNC_MEMORY_ALL_OUTB;
1415 * maybe we have to do work on our outbound queues... at least
1416 * we have to check the outbound-int-capable thinint-capable
1419 if (q->hydra_gives_outbound_pcis) {
1420 irq_ptr = (struct qdio_irq*)q->irq_ptr;
1421 for (i=0;i<irq_ptr->no_output_qs;i++) {
1422 oq = irq_ptr->output_qs[i];
1423 if (!qdio_is_outbound_q_done(oq)) {
1424 qdio_perf_stat_dec(&perf_stats.tl_runs);
1425 __qdio_outbound_processing(oq);
1430 if (!qdio_has_inbound_q_moved(q))
1433 qdio_kick_inbound_handler(q);
1434 if (tiqdio_is_inbound_q_done(q))
1435 if (!qdio_stop_polling(q)) {
1437 * we set the flags to get into the stuff next time,
1438 * see also comment in qdio_stop_polling
1440 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1448 tiqdio_inbound_processing(unsigned long q)
1450 __tiqdio_inbound_processing((struct qdio_q *) q,
1451 atomic_read(&spare_indicator_usecount));
1455 __qdio_inbound_processing(struct qdio_q *q)
1459 QDIO_DBF_TEXT4(0,trace,"qinproc");
1460 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1462 if (unlikely(qdio_reserve_q(q))) {
1464 qdio_perf_stat_inc(&perf_stats.inbound_tl_runs_resched);
1465 /* as we're sissies, we'll check next time */
1466 if (likely(!atomic_read(&q->is_in_shutdown))) {
1468 QDIO_DBF_TEXT4(0,trace,"busy,agn");
1472 qdio_perf_stat_inc(&perf_stats.inbound_tl_runs);
1473 qdio_perf_stat_inc(&perf_stats.tl_runs);
1476 if (qdio_has_inbound_q_moved(q)) {
1477 qdio_kick_inbound_handler(q);
1478 if (!qdio_stop_polling(q)) {
1480 if (q_laps<QDIO_Q_LAPS)
1485 if (!qdio_is_inbound_q_done(q))
1486 /* means poll time is not yet over */
1494 qdio_inbound_processing(unsigned long q)
1496 __qdio_inbound_processing((struct qdio_q *) q);
1499 /************************* MAIN ROUTINES *******************************/
1501 #ifdef QDIO_USE_PROCESSING_STATE
1503 tiqdio_reset_processing_state(struct qdio_q *q, int q_laps)
1511 * under VM, we have not used the PROCESSING state, so no
1512 * need to stop polling
1517 if (unlikely(qdio_reserve_q(q))) {
1519 qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs_resched);
1521 * as we might just be about to stop polling, we make
1522 * sure that we check again at least once more
1526 * sanity -- we'd get here without setting the
1529 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1533 if (qdio_stop_polling(q)) {
1537 if (q_laps<QDIO_Q_LAPS-1) {
1542 * we set the flags to get into the stuff
1543 * next time, see also comment in qdio_stop_polling
1545 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1551 #endif /* QDIO_USE_PROCESSING_STATE */
1554 tiqdio_inbound_checks(void)
1557 int spare_ind_was_set=0;
1558 #ifdef QDIO_USE_PROCESSING_STATE
1560 #endif /* QDIO_USE_PROCESSING_STATE */
1562 QDIO_DBF_TEXT4(0,trace,"iqdinbck");
1563 QDIO_DBF_TEXT5(0,trace,"iqlocsum");
1565 #ifdef QDIO_USE_PROCESSING_STATE
1567 #endif /* QDIO_USE_PROCESSING_STATE */
1569 /* when the spare indicator is used and set, save that and clear it */
1570 if ((atomic_read(&spare_indicator_usecount)) && spare_indicator) {
1571 spare_ind_was_set = 1;
1572 tiqdio_clear_summary_bit((__u32*)&spare_indicator);
1575 q=(struct qdio_q*)tiq_list;
1579 __tiqdio_inbound_processing(q, spare_ind_was_set);
1580 q=(struct qdio_q*)q->list_next;
1581 } while (q!=(struct qdio_q*)tiq_list);
1583 #ifdef QDIO_USE_PROCESSING_STATE
1584 q=(struct qdio_q*)tiq_list;
1588 ret = tiqdio_reset_processing_state(q, q_laps);
1595 q = (struct qdio_q*)q->list_next;
1601 } while (q!=(struct qdio_q*)tiq_list);
1602 #endif /* QDIO_USE_PROCESSING_STATE */
1606 tiqdio_tl(unsigned long data)
1608 QDIO_DBF_TEXT4(0,trace,"iqdio_tl");
1610 qdio_perf_stat_inc(&perf_stats.tl_runs);
1612 tiqdio_inbound_checks();
1615 /********************* GENERAL HELPER_ROUTINES ***********************/
1618 qdio_release_irq_memory(struct qdio_irq *irq_ptr)
1623 for (i = 0; i < QDIO_MAX_QUEUES_PER_IRQ; i++) {
1624 q = irq_ptr->input_qs[i];
1626 free_page((unsigned long) q->slib);
1627 kmem_cache_free(qdio_q_cache, q);
1629 q = irq_ptr->output_qs[i];
1631 free_page((unsigned long) q->slib);
1632 kmem_cache_free(qdio_q_cache, q);
1635 free_page((unsigned long) irq_ptr->qdr);
1636 free_page((unsigned long) irq_ptr);
1640 qdio_set_impl_params(struct qdio_irq *irq_ptr,
1641 unsigned int qib_param_field_format,
1642 /* pointer to 128 bytes or NULL, if no param field */
1643 unsigned char *qib_param_field,
1644 /* pointer to no_queues*128 words of data or NULL */
1645 unsigned int no_input_qs,
1646 unsigned int no_output_qs,
1647 unsigned long *input_slib_elements,
1648 unsigned long *output_slib_elements)
1655 irq_ptr->qib.pfmt=qib_param_field_format;
1656 if (qib_param_field)
1657 memcpy(irq_ptr->qib.parm,qib_param_field,
1658 QDIO_MAX_BUFFERS_PER_Q);
1660 if (input_slib_elements)
1661 for (i=0;i<no_input_qs;i++) {
1662 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1663 irq_ptr->input_qs[i]->slib->slibe[j].parms=
1664 input_slib_elements[
1665 i*QDIO_MAX_BUFFERS_PER_Q+j];
1667 if (output_slib_elements)
1668 for (i=0;i<no_output_qs;i++) {
1669 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1670 irq_ptr->output_qs[i]->slib->slibe[j].parms=
1671 output_slib_elements[
1672 i*QDIO_MAX_BUFFERS_PER_Q+j];
1677 qdio_alloc_qs(struct qdio_irq *irq_ptr,
1678 int no_input_qs, int no_output_qs)
1683 for (i = 0; i < no_input_qs; i++) {
1684 q = kmem_cache_alloc(qdio_q_cache, GFP_KERNEL);
1687 memset(q, 0, sizeof(*q));
1689 q->slib = (struct slib *) __get_free_page(GFP_KERNEL);
1691 kmem_cache_free(qdio_q_cache, q);
1694 irq_ptr->input_qs[i]=q;
1697 for (i = 0; i < no_output_qs; i++) {
1698 q = kmem_cache_alloc(qdio_q_cache, GFP_KERNEL);
1701 memset(q, 0, sizeof(*q));
1703 q->slib = (struct slib *) __get_free_page(GFP_KERNEL);
1705 kmem_cache_free(qdio_q_cache, q);
1708 irq_ptr->output_qs[i]=q;
1714 qdio_fill_qs(struct qdio_irq *irq_ptr, struct ccw_device *cdev,
1715 int no_input_qs, int no_output_qs,
1716 qdio_handler_t *input_handler,
1717 qdio_handler_t *output_handler,
1718 unsigned long int_parm,int q_format,
1719 unsigned long flags,
1720 void **inbound_sbals_array,
1721 void **outbound_sbals_array)
1725 char dbf_text[20]; /* see qdio_initialize */
1729 sprintf(dbf_text,"qfqs%4x",cdev->private->schid.sch_no);
1730 QDIO_DBF_TEXT0(0,setup,dbf_text);
1731 for (i=0;i<no_input_qs;i++) {
1732 q=irq_ptr->input_qs[i];
1734 memset(q,0,((char*)&q->slib)-((char*)q));
1735 sprintf(dbf_text,"in-q%4x",i);
1736 QDIO_DBF_TEXT0(0,setup,dbf_text);
1737 QDIO_DBF_HEX0(0,setup,&q,sizeof(void*));
1739 memset(q->slib,0,PAGE_SIZE);
1740 q->sl=(struct sl*)(((char*)q->slib)+PAGE_SIZE/2);
1744 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1745 q->sbal[j]=*(inbound_sbals_array++);
1747 q->queue_type=q_format;
1748 q->int_parm=int_parm;
1749 q->schid = irq_ptr->schid;
1750 q->irq_ptr = irq_ptr;
1755 q->first_to_check=0;
1757 q->handler=input_handler;
1758 q->dev_st_chg_ind=irq_ptr->dev_st_chg_ind;
1760 /* q->is_thinint_q isn't valid at this time, but
1761 * irq_ptr->is_thinint_irq is
1763 if (irq_ptr->is_thinint_irq)
1764 tasklet_init(&q->tasklet, tiqdio_inbound_processing,
1767 tasklet_init(&q->tasklet, qdio_inbound_processing,
1770 /* actually this is not used for inbound queues. yet. */
1771 atomic_set(&q->busy_siga_counter,0);
1772 q->timing.busy_start=0;
1774 /* for (j=0;j<QDIO_STATS_NUMBER;j++)
1775 q->timing.last_transfer_times[j]=(qdio_get_micros()/
1776 QDIO_STATS_NUMBER)*j;
1777 q->timing.last_transfer_index=QDIO_STATS_NUMBER-1;
1781 if (i>0) irq_ptr->input_qs[i-1]->slib->nsliba=
1782 (unsigned long)(q->slib);
1783 q->slib->sla=(unsigned long)(q->sl);
1784 q->slib->slsba=(unsigned long)(&q->slsb.acc.val[0]);
1787 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1788 q->sl->element[j].sbal=(unsigned long)(q->sbal[j]);
1790 QDIO_DBF_TEXT2(0,setup,"sl-sb-b0");
1792 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1793 ptr=(void*)&q->slsb;
1794 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1795 ptr=(void*)q->sbal[0];
1796 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1799 if (!irq_ptr->is_qebsm) {
1800 unsigned int count = 1;
1801 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
1802 set_slsb(q, &j, SLSB_P_INPUT_NOT_INIT, &count);
1806 for (i=0;i<no_output_qs;i++) {
1807 q=irq_ptr->output_qs[i];
1808 memset(q,0,((char*)&q->slib)-((char*)q));
1810 sprintf(dbf_text,"outq%4x",i);
1811 QDIO_DBF_TEXT0(0,setup,dbf_text);
1812 QDIO_DBF_HEX0(0,setup,&q,sizeof(void*));
1814 memset(q->slib,0,PAGE_SIZE);
1815 q->sl=(struct sl*)(((char*)q->slib)+PAGE_SIZE/2);
1819 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1820 q->sbal[j]=*(outbound_sbals_array++);
1822 q->queue_type=q_format;
1823 if ((q->queue_type == QDIO_IQDIO_QFMT) &&
1824 (no_output_qs > 1) &&
1825 (i == no_output_qs-1))
1826 q->queue_type = QDIO_IQDIO_QFMT_ASYNCH;
1827 q->int_parm=int_parm;
1830 q->schid = irq_ptr->schid;
1832 q->irq_ptr = irq_ptr;
1835 q->first_to_check=0;
1837 q->handler=output_handler;
1839 tasklet_init(&q->tasklet, qdio_outbound_processing,
1841 setup_timer(&q->timer, qdio_outbound_processing,
1844 atomic_set(&q->busy_siga_counter,0);
1845 q->timing.busy_start=0;
1848 if (i>0) irq_ptr->output_qs[i-1]->slib->nsliba=
1849 (unsigned long)(q->slib);
1850 q->slib->sla=(unsigned long)(q->sl);
1851 q->slib->slsba=(unsigned long)(&q->slsb.acc.val[0]);
1854 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1855 q->sl->element[j].sbal=(unsigned long)(q->sbal[j]);
1857 QDIO_DBF_TEXT2(0,setup,"sl-sb-b0");
1859 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1860 ptr=(void*)&q->slsb;
1861 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1862 ptr=(void*)q->sbal[0];
1863 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1866 if (!irq_ptr->is_qebsm) {
1867 unsigned int count = 1;
1868 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
1869 set_slsb(q, &j, SLSB_P_OUTPUT_NOT_INIT, &count);
1875 qdio_fill_thresholds(struct qdio_irq *irq_ptr,
1876 unsigned int no_input_qs,
1877 unsigned int no_output_qs,
1878 unsigned int min_input_threshold,
1879 unsigned int max_input_threshold,
1880 unsigned int min_output_threshold,
1881 unsigned int max_output_threshold)
1886 for (i=0;i<no_input_qs;i++) {
1887 q=irq_ptr->input_qs[i];
1888 q->timing.threshold=max_input_threshold;
1889 /* for (j=0;j<QDIO_STATS_CLASSES;j++) {
1890 q->threshold_classes[j].threshold=
1891 min_input_threshold+
1892 (max_input_threshold-min_input_threshold)/
1895 qdio_use_thresholds(q,QDIO_STATS_CLASSES/2);*/
1897 for (i=0;i<no_output_qs;i++) {
1898 q=irq_ptr->output_qs[i];
1899 q->timing.threshold=max_output_threshold;
1900 /* for (j=0;j<QDIO_STATS_CLASSES;j++) {
1901 q->threshold_classes[j].threshold=
1902 min_output_threshold+
1903 (max_output_threshold-min_output_threshold)/
1906 qdio_use_thresholds(q,QDIO_STATS_CLASSES/2);*/
1910 static void tiqdio_thinint_handler(void *ind, void *drv_data)
1912 QDIO_DBF_TEXT4(0,trace,"thin_int");
1914 qdio_perf_stat_inc(&perf_stats.thinints);
1916 /* SVS only when needed:
1917 * issue SVS to benefit from iqdio interrupt avoidance
1918 * (SVS clears AISOI)*/
1920 tiqdio_clear_global_summary();
1922 tiqdio_inbound_checks();
1926 qdio_set_state(struct qdio_irq *irq_ptr, enum qdio_irq_states state)
1929 #ifdef CONFIG_QDIO_DEBUG
1932 QDIO_DBF_TEXT5(0,trace,"newstate");
1933 sprintf(dbf_text,"%4x%4x",irq_ptr->schid.sch_no,state);
1934 QDIO_DBF_TEXT5(0,trace,dbf_text);
1935 #endif /* CONFIG_QDIO_DEBUG */
1937 irq_ptr->state=state;
1938 for (i=0;i<irq_ptr->no_input_qs;i++)
1939 irq_ptr->input_qs[i]->state=state;
1940 for (i=0;i<irq_ptr->no_output_qs;i++)
1941 irq_ptr->output_qs[i]->state=state;
1946 qdio_irq_check_sense(struct subchannel_id schid, struct irb *irb)
1950 if (irb->esw.esw0.erw.cons) {
1951 sprintf(dbf_text,"sens%4x",schid.sch_no);
1952 QDIO_DBF_TEXT2(1,trace,dbf_text);
1953 QDIO_DBF_HEX0(0,sense,irb,QDIO_DBF_SENSE_LEN);
1955 QDIO_PRINT_WARN("sense data available on qdio channel.\n");
1956 QDIO_HEXDUMP16(WARN,"irb: ",irb);
1957 QDIO_HEXDUMP16(WARN,"sense data: ",irb->ecw);
1963 qdio_handle_pci(struct qdio_irq *irq_ptr)
1968 qdio_perf_stat_inc(&perf_stats.pcis);
1969 for (i=0;i<irq_ptr->no_input_qs;i++) {
1970 q=irq_ptr->input_qs[i];
1971 if (q->is_input_q&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT)
1974 qdio_perf_stat_dec(&perf_stats.tl_runs);
1975 __qdio_inbound_processing(q);
1978 if (!irq_ptr->hydra_gives_outbound_pcis)
1980 for (i=0;i<irq_ptr->no_output_qs;i++) {
1981 q=irq_ptr->output_qs[i];
1982 if (qdio_is_outbound_q_done(q))
1984 qdio_perf_stat_dec(&perf_stats.tl_runs);
1985 if (!irq_ptr->sync_done_on_outb_pcis)
1987 __qdio_outbound_processing(q);
1991 static void qdio_establish_handle_irq(struct ccw_device*, int, int);
1994 qdio_handle_activate_check(struct ccw_device *cdev, unsigned long intparm,
1995 int cstat, int dstat)
1997 struct qdio_irq *irq_ptr;
2001 irq_ptr = cdev->private->qdio_data;
2003 QDIO_DBF_TEXT2(1, trace, "ick2");
2004 sprintf(dbf_text,"%s", cdev->dev.bus_id);
2005 QDIO_DBF_TEXT2(1,trace,dbf_text);
2006 QDIO_DBF_HEX2(0,trace,&intparm,sizeof(int));
2007 QDIO_DBF_HEX2(0,trace,&dstat,sizeof(int));
2008 QDIO_DBF_HEX2(0,trace,&cstat,sizeof(int));
2009 QDIO_PRINT_ERR("received check condition on activate " \
2010 "queues on device %s (cs=x%x, ds=x%x).\n",
2011 cdev->dev.bus_id, cstat, dstat);
2012 if (irq_ptr->no_input_qs) {
2013 q=irq_ptr->input_qs[0];
2014 } else if (irq_ptr->no_output_qs) {
2015 q=irq_ptr->output_qs[0];
2017 QDIO_PRINT_ERR("oops... no queue registered for device %s!?\n",
2019 goto omit_handler_call;
2021 q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION|
2022 QDIO_STATUS_LOOK_FOR_ERROR,
2023 0,0,0,-1,-1,q->int_parm);
2025 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_STOPPED);
2030 qdio_call_shutdown(struct work_struct *work)
2032 struct ccw_device_private *priv;
2033 struct ccw_device *cdev;
2035 priv = container_of(work, struct ccw_device_private, kick_work);
2037 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
2038 put_device(&cdev->dev);
2042 qdio_timeout_handler(struct ccw_device *cdev)
2044 struct qdio_irq *irq_ptr;
2047 QDIO_DBF_TEXT2(0, trace, "qtoh");
2048 sprintf(dbf_text, "%s", cdev->dev.bus_id);
2049 QDIO_DBF_TEXT2(0, trace, dbf_text);
2051 irq_ptr = cdev->private->qdio_data;
2052 sprintf(dbf_text, "state:%d", irq_ptr->state);
2053 QDIO_DBF_TEXT2(0, trace, dbf_text);
2055 switch (irq_ptr->state) {
2056 case QDIO_IRQ_STATE_INACTIVE:
2057 QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: timed out\n",
2058 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2059 QDIO_DBF_TEXT2(1,setup,"eq:timeo");
2060 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2062 case QDIO_IRQ_STATE_CLEANUP:
2063 QDIO_PRINT_INFO("Did not get interrupt on cleanup, "
2065 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2066 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2068 case QDIO_IRQ_STATE_ESTABLISHED:
2069 case QDIO_IRQ_STATE_ACTIVE:
2070 /* I/O has been terminated by common I/O layer. */
2071 QDIO_PRINT_INFO("Queues on irq 0.%x.%04x killed by cio.\n",
2072 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2073 QDIO_DBF_TEXT2(1, trace, "cio:term");
2074 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
2075 if (get_device(&cdev->dev)) {
2076 /* Can't call shutdown from interrupt context. */
2077 PREPARE_WORK(&cdev->private->kick_work,
2078 qdio_call_shutdown);
2079 queue_work(ccw_device_work, &cdev->private->kick_work);
2085 ccw_device_set_timeout(cdev, 0);
2086 wake_up(&cdev->private->wait_q);
2090 qdio_handler(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
2092 struct qdio_irq *irq_ptr;
2096 #ifdef CONFIG_QDIO_DEBUG
2097 QDIO_DBF_TEXT4(0, trace, "qint");
2098 sprintf(dbf_text, "%s", cdev->dev.bus_id);
2099 QDIO_DBF_TEXT4(0, trace, dbf_text);
2100 #endif /* CONFIG_QDIO_DEBUG */
2103 QDIO_PRINT_ERR("got unsolicited interrupt in qdio " \
2104 "handler, device %s\n", cdev->dev.bus_id);
2108 irq_ptr = cdev->private->qdio_data;
2110 QDIO_DBF_TEXT2(1, trace, "uint");
2111 sprintf(dbf_text,"%s", cdev->dev.bus_id);
2112 QDIO_DBF_TEXT2(1,trace,dbf_text);
2113 QDIO_PRINT_ERR("received interrupt on unused device %s!\n",
2119 /* Currently running i/o is in error. */
2120 switch (PTR_ERR(irb)) {
2122 QDIO_PRINT_ERR("i/o error on device %s\n",
2126 qdio_timeout_handler(cdev);
2129 QDIO_PRINT_ERR("unknown error state %ld on device %s\n",
2130 PTR_ERR(irb), cdev->dev.bus_id);
2135 qdio_irq_check_sense(irq_ptr->schid, irb);
2137 #ifdef CONFIG_QDIO_DEBUG
2138 sprintf(dbf_text, "state:%d", irq_ptr->state);
2139 QDIO_DBF_TEXT4(0, trace, dbf_text);
2140 #endif /* CONFIG_QDIO_DEBUG */
2142 cstat = irb->scsw.cstat;
2143 dstat = irb->scsw.dstat;
2145 switch (irq_ptr->state) {
2146 case QDIO_IRQ_STATE_INACTIVE:
2147 qdio_establish_handle_irq(cdev, cstat, dstat);
2150 case QDIO_IRQ_STATE_CLEANUP:
2151 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2154 case QDIO_IRQ_STATE_ESTABLISHED:
2155 case QDIO_IRQ_STATE_ACTIVE:
2156 if (cstat & SCHN_STAT_PCI) {
2157 qdio_handle_pci(irq_ptr);
2161 if ((cstat&~SCHN_STAT_PCI)||dstat) {
2162 qdio_handle_activate_check(cdev, intparm, cstat, dstat);
2166 QDIO_PRINT_ERR("got interrupt for queues in state %d on " \
2168 irq_ptr->state, cdev->dev.bus_id);
2170 wake_up(&cdev->private->wait_q);
2175 qdio_synchronize(struct ccw_device *cdev, unsigned int flags,
2176 unsigned int queue_number)
2180 struct qdio_irq *irq_ptr;
2182 #ifdef CONFIG_QDIO_DEBUG
2183 char dbf_text[15]="SyncXXXX";
2186 irq_ptr = cdev->private->qdio_data;
2190 #ifdef CONFIG_QDIO_DEBUG
2191 *((int*)(&dbf_text[4])) = irq_ptr->schid.sch_no;
2192 QDIO_DBF_HEX4(0,trace,dbf_text,QDIO_DBF_TRACE_LEN);
2193 *((int*)(&dbf_text[0]))=flags;
2194 *((int*)(&dbf_text[4]))=queue_number;
2195 QDIO_DBF_HEX4(0,trace,dbf_text,QDIO_DBF_TRACE_LEN);
2196 #endif /* CONFIG_QDIO_DEBUG */
2198 if (flags&QDIO_FLAG_SYNC_INPUT) {
2199 q=irq_ptr->input_qs[queue_number];
2202 if (!(irq_ptr->is_qebsm))
2203 cc = do_siga_sync(q->schid, 0, q->mask);
2204 } else if (flags&QDIO_FLAG_SYNC_OUTPUT) {
2205 q=irq_ptr->output_qs[queue_number];
2208 if (!(irq_ptr->is_qebsm))
2209 cc = do_siga_sync(q->schid, q->mask, 0);
2215 QDIO_DBF_HEX3(0,trace,&ptr,sizeof(int));
2221 qdio_get_ssqd_information(struct subchannel_id *schid,
2222 struct qdio_chsc_ssqd **ssqd_area)
2226 QDIO_DBF_TEXT0(0, setup, "getssqd");
2227 *ssqd_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC);
2229 QDIO_PRINT_WARN("Could not get memory for chsc on sch x%x.\n",
2234 (*ssqd_area)->request = (struct chsc_header) {
2238 (*ssqd_area)->first_sch = schid->sch_no;
2239 (*ssqd_area)->last_sch = schid->sch_no;
2240 (*ssqd_area)->ssid = schid->ssid;
2241 result = chsc(*ssqd_area);
2244 QDIO_PRINT_WARN("CHSC returned cc %i on sch 0.%x.%x.\n",
2245 result, schid->ssid, schid->sch_no);
2249 if ((*ssqd_area)->response.code != QDIO_CHSC_RESPONSE_CODE_OK) {
2250 QDIO_PRINT_WARN("CHSC response is 0x%x on sch 0.%x.%x.\n",
2251 (*ssqd_area)->response.code,
2252 schid->ssid, schid->sch_no);
2255 if (!((*ssqd_area)->flags & CHSC_FLAG_QDIO_CAPABILITY) ||
2256 !((*ssqd_area)->flags & CHSC_FLAG_VALIDITY) ||
2257 ((*ssqd_area)->sch != schid->sch_no)) {
2258 QDIO_PRINT_WARN("huh? problems checking out sch 0.%x.%x... " \
2259 "using all SIGAs.\n",
2260 schid->ssid, schid->sch_no);
2269 qdio_get_ssqd_pct(struct ccw_device *cdev)
2271 struct qdio_chsc_ssqd *ssqd_area;
2272 struct subchannel_id schid;
2277 QDIO_DBF_TEXT0(0, setup, "getpct");
2278 schid = ccw_device_get_subchannel_id(cdev);
2279 rc = qdio_get_ssqd_information(&schid, &ssqd_area);
2281 pct = (int)ssqd_area->pct;
2283 mempool_free(ssqd_area, qdio_mempool_scssc);
2284 sprintf(dbf_text, "pct: %d", pct);
2285 QDIO_DBF_TEXT2(0, setup, dbf_text);
2288 EXPORT_SYMBOL(qdio_get_ssqd_pct);
2291 qdio_check_subchannel_qebsm(struct qdio_irq *irq_ptr, unsigned long token)
2295 unsigned int count, start_buf;
2298 /*check if QEBSM is disabled */
2299 if (!(irq_ptr->is_qebsm) || !(irq_ptr->qdioac & 0x01)) {
2300 irq_ptr->is_qebsm = 0;
2301 irq_ptr->sch_token = 0;
2302 irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM;
2303 QDIO_DBF_TEXT0(0,setup,"noV=V");
2306 irq_ptr->sch_token = token;
2308 for (i = 0; i < irq_ptr->no_input_qs;i++) {
2309 q = irq_ptr->input_qs[i];
2310 count = QDIO_MAX_BUFFERS_PER_Q;
2312 set_slsb(q, &start_buf, SLSB_P_INPUT_NOT_INIT, &count);
2314 sprintf(dbf_text,"V=V:%2x",irq_ptr->is_qebsm);
2315 QDIO_DBF_TEXT0(0,setup,dbf_text);
2316 sprintf(dbf_text,"%8lx",irq_ptr->sch_token);
2317 QDIO_DBF_TEXT0(0,setup,dbf_text);
2319 for (i = 0; i < irq_ptr->no_output_qs; i++) {
2320 q = irq_ptr->output_qs[i];
2321 count = QDIO_MAX_BUFFERS_PER_Q;
2323 set_slsb(q, &start_buf, SLSB_P_OUTPUT_NOT_INIT, &count);
2328 qdio_get_ssqd_siga(struct qdio_irq *irq_ptr)
2331 struct qdio_chsc_ssqd *ssqd_area;
2333 QDIO_DBF_TEXT0(0,setup,"getssqd");
2334 irq_ptr->qdioac = 0;
2335 rc = qdio_get_ssqd_information(&irq_ptr->schid, &ssqd_area);
2337 QDIO_PRINT_WARN("using all SIGAs for sch x%x.n",
2338 irq_ptr->schid.sch_no);
2339 irq_ptr->qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY |
2340 CHSC_FLAG_SIGA_OUTPUT_NECESSARY |
2341 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */
2342 irq_ptr->is_qebsm = 0;
2344 irq_ptr->qdioac = ssqd_area->qdioac1;
2346 qdio_check_subchannel_qebsm(irq_ptr, ssqd_area->sch_token);
2348 mempool_free(ssqd_area, qdio_mempool_scssc);
2352 tiqdio_check_chsc_availability(void)
2356 if (!css_characteristics_avail)
2359 /* Check for bit 41. */
2360 if (!css_general_characteristics.aif) {
2361 QDIO_PRINT_WARN("Adapter interruption facility not " \
2366 /* Check for bits 107 and 108. */
2367 if (!css_chsc_characteristics.scssc ||
2368 !css_chsc_characteristics.scsscf) {
2369 QDIO_PRINT_WARN("Set Chan Subsys. Char. & Fast-CHSCs " \
2370 "not available.\n");
2374 /* Check for OSA/FCP thin interrupts (bit 67). */
2375 hydra_thinints = css_general_characteristics.aif_osa;
2376 sprintf(dbf_text,"hydrati%1x", hydra_thinints);
2377 QDIO_DBF_TEXT0(0,setup,dbf_text);
2380 /* Check for QEBSM support in general (bit 58). */
2381 is_passthrough = css_general_characteristics.qebsm;
2383 sprintf(dbf_text,"cssQBS:%1x", is_passthrough);
2384 QDIO_DBF_TEXT0(0,setup,dbf_text);
2386 /* Check for aif time delay disablement fac (bit 56). If installed,
2387 * omit svs even under lpar (good point by rick again) */
2388 omit_svs = css_general_characteristics.aif_tdd;
2389 sprintf(dbf_text,"omitsvs%1x", omit_svs);
2390 QDIO_DBF_TEXT0(0,setup,dbf_text);
2396 tiqdio_set_subchannel_ind(struct qdio_irq *irq_ptr, int reset_to_zero)
2398 unsigned long real_addr_local_summary_bit;
2399 unsigned long real_addr_dev_st_chg_ind;
2403 unsigned int resp_code;
2407 struct chsc_header request;
2412 u64 summary_indicator_addr;
2413 u64 subchannel_indicator_addr;
2418 u32 word_with_d_bit;
2419 /* set to 0x10000000 to enable
2420 * time delay disablement facility */
2422 struct subchannel_id schid;
2423 u32 reserved6[1004];
2424 struct chsc_header response;
2428 if (!irq_ptr->is_thinint_irq)
2431 if (reset_to_zero) {
2432 real_addr_local_summary_bit=0;
2433 real_addr_dev_st_chg_ind=0;
2435 real_addr_local_summary_bit=
2436 virt_to_phys((volatile void *)tiqdio_ind);
2437 real_addr_dev_st_chg_ind=
2438 virt_to_phys((volatile void *)irq_ptr->dev_st_chg_ind);
2441 scssc_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC);
2443 QDIO_PRINT_WARN("No memory for setting indicators on " \
2444 "subchannel 0.%x.%x.\n",
2445 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2448 scssc_area->request = (struct chsc_header) {
2452 scssc_area->operation_code = 0;
2454 scssc_area->summary_indicator_addr = real_addr_local_summary_bit;
2455 scssc_area->subchannel_indicator_addr = real_addr_dev_st_chg_ind;
2456 scssc_area->ks = QDIO_STORAGE_KEY;
2457 scssc_area->kc = QDIO_STORAGE_KEY;
2458 scssc_area->isc = TIQDIO_THININT_ISC;
2459 scssc_area->schid = irq_ptr->schid;
2460 /* enables the time delay disablement facility. Don't care
2461 * whether it is really there (i.e. we haven't checked for
2463 if (css_general_characteristics.aif_tdd)
2464 scssc_area->word_with_d_bit = 0x10000000;
2466 QDIO_PRINT_WARN("Time delay disablement facility " \
2469 result = chsc(scssc_area);
2471 QDIO_PRINT_WARN("could not set indicators on irq 0.%x.%x, " \
2473 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,result);
2478 resp_code = scssc_area->response.code;
2479 if (resp_code!=QDIO_CHSC_RESPONSE_CODE_OK) {
2480 QDIO_PRINT_WARN("response upon setting indicators " \
2481 "is 0x%x.\n",resp_code);
2482 sprintf(dbf_text,"sidR%4x",resp_code);
2483 QDIO_DBF_TEXT1(0,trace,dbf_text);
2484 QDIO_DBF_TEXT1(0,setup,dbf_text);
2485 ptr=&scssc_area->response;
2486 QDIO_DBF_HEX2(1,setup,&ptr,QDIO_DBF_SETUP_LEN);
2491 QDIO_DBF_TEXT2(0,setup,"setscind");
2492 QDIO_DBF_HEX2(0,setup,&real_addr_local_summary_bit,
2493 sizeof(unsigned long));
2494 QDIO_DBF_HEX2(0,setup,&real_addr_dev_st_chg_ind,sizeof(unsigned long));
2497 mempool_free(scssc_area, qdio_mempool_scssc);
2503 tiqdio_set_delay_target(struct qdio_irq *irq_ptr, unsigned long delay_target)
2505 unsigned int resp_code;
2511 struct chsc_header request;
2518 u32 reserved5[1009];
2519 struct chsc_header response;
2523 if (!irq_ptr->is_thinint_irq)
2526 scsscf_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC);
2528 QDIO_PRINT_WARN("No memory for setting delay target on " \
2529 "subchannel 0.%x.%x.\n",
2530 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2533 scsscf_area->request = (struct chsc_header) {
2538 scsscf_area->delay_target = delay_target<<16;
2540 result=chsc(scsscf_area);
2542 QDIO_PRINT_WARN("could not set delay target on irq 0.%x.%x, " \
2543 "cc=%i. Continuing.\n",
2544 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
2550 resp_code = scsscf_area->response.code;
2551 if (resp_code!=QDIO_CHSC_RESPONSE_CODE_OK) {
2552 QDIO_PRINT_WARN("response upon setting delay target " \
2553 "is 0x%x. Continuing.\n",resp_code);
2554 sprintf(dbf_text,"sdtR%4x",resp_code);
2555 QDIO_DBF_TEXT1(0,trace,dbf_text);
2556 QDIO_DBF_TEXT1(0,setup,dbf_text);
2557 ptr=&scsscf_area->response;
2558 QDIO_DBF_HEX2(1,trace,&ptr,QDIO_DBF_TRACE_LEN);
2560 QDIO_DBF_TEXT2(0,trace,"delytrgt");
2561 QDIO_DBF_HEX2(0,trace,&delay_target,sizeof(unsigned long));
2562 result = 0; /* not critical */
2564 mempool_free(scsscf_area, qdio_mempool_scssc);
2569 qdio_cleanup(struct ccw_device *cdev, int how)
2571 struct qdio_irq *irq_ptr;
2575 irq_ptr = cdev->private->qdio_data;
2579 sprintf(dbf_text,"qcln%4x",irq_ptr->schid.sch_no);
2580 QDIO_DBF_TEXT1(0,trace,dbf_text);
2581 QDIO_DBF_TEXT0(0,setup,dbf_text);
2583 rc = qdio_shutdown(cdev, how);
2584 if ((rc == 0) || (rc == -EINPROGRESS))
2585 rc = qdio_free(cdev);
2590 qdio_shutdown(struct ccw_device *cdev, int how)
2592 struct qdio_irq *irq_ptr;
2596 unsigned long flags;
2600 irq_ptr = cdev->private->qdio_data;
2604 down(&irq_ptr->setting_up_sema);
2606 sprintf(dbf_text,"qsqs%4x",irq_ptr->schid.sch_no);
2607 QDIO_DBF_TEXT1(0,trace,dbf_text);
2608 QDIO_DBF_TEXT0(0,setup,dbf_text);
2610 /* mark all qs as uninteresting */
2611 for (i=0;i<irq_ptr->no_input_qs;i++)
2612 atomic_set(&irq_ptr->input_qs[i]->is_in_shutdown,1);
2614 for (i=0;i<irq_ptr->no_output_qs;i++)
2615 atomic_set(&irq_ptr->output_qs[i]->is_in_shutdown,1);
2617 tasklet_kill(&tiqdio_tasklet);
2619 for (i=0;i<irq_ptr->no_input_qs;i++) {
2620 qdio_unmark_q(irq_ptr->input_qs[i]);
2621 tasklet_kill(&irq_ptr->input_qs[i]->tasklet);
2622 wait_event_interruptible_timeout(cdev->private->wait_q,
2623 !atomic_read(&irq_ptr->
2626 QDIO_NO_USE_COUNT_TIMEOUT);
2627 if (atomic_read(&irq_ptr->input_qs[i]->use_count))
2628 result=-EINPROGRESS;
2631 for (i=0;i<irq_ptr->no_output_qs;i++) {
2632 tasklet_kill(&irq_ptr->output_qs[i]->tasklet);
2633 del_timer(&irq_ptr->output_qs[i]->timer);
2634 wait_event_interruptible_timeout(cdev->private->wait_q,
2635 !atomic_read(&irq_ptr->
2638 QDIO_NO_USE_COUNT_TIMEOUT);
2639 if (atomic_read(&irq_ptr->output_qs[i]->use_count))
2640 result=-EINPROGRESS;
2643 /* cleanup subchannel */
2644 spin_lock_irqsave(get_ccwdev_lock(cdev),flags);
2645 if (how&QDIO_FLAG_CLEANUP_USING_CLEAR) {
2646 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
2647 timeout=QDIO_CLEANUP_CLEAR_TIMEOUT;
2648 } else if (how&QDIO_FLAG_CLEANUP_USING_HALT) {
2649 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
2650 timeout=QDIO_CLEANUP_HALT_TIMEOUT;
2651 } else { /* default behaviour */
2652 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
2653 timeout=QDIO_CLEANUP_HALT_TIMEOUT;
2655 if (rc == -ENODEV) {
2656 /* No need to wait for device no longer present. */
2657 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2658 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2659 } else if (((void *)cdev->handler != (void *)qdio_handler) && rc == 0) {
2661 * Whoever put another handler there, has to cope with the
2662 * interrupt theirself. Might happen if qdio_shutdown was
2663 * called on already shutdown queues, but this shouldn't have
2666 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2667 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2668 } else if (rc == 0) {
2669 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
2670 ccw_device_set_timeout(cdev, timeout);
2671 spin_unlock_irqrestore(get_ccwdev_lock(cdev),flags);
2673 wait_event(cdev->private->wait_q,
2674 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
2675 irq_ptr->state == QDIO_IRQ_STATE_ERR);
2677 QDIO_PRINT_INFO("ccw_device_{halt,clear} returned %d for "
2678 "device %s\n", result, cdev->dev.bus_id);
2679 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2683 if (irq_ptr->is_thinint_irq) {
2684 qdio_put_indicator((__u32*)irq_ptr->dev_st_chg_ind);
2685 tiqdio_set_subchannel_ind(irq_ptr,1);
2686 /* reset adapter interrupt indicators */
2689 /* exchange int handlers, if necessary */
2690 if ((void*)cdev->handler == (void*)qdio_handler)
2691 cdev->handler=irq_ptr->original_int_handler;
2693 /* Ignore errors. */
2694 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2695 ccw_device_set_timeout(cdev, 0);
2697 up(&irq_ptr->setting_up_sema);
2702 qdio_free(struct ccw_device *cdev)
2704 struct qdio_irq *irq_ptr;
2707 irq_ptr = cdev->private->qdio_data;
2711 down(&irq_ptr->setting_up_sema);
2713 sprintf(dbf_text,"qfqs%4x",irq_ptr->schid.sch_no);
2714 QDIO_DBF_TEXT1(0,trace,dbf_text);
2715 QDIO_DBF_TEXT0(0,setup,dbf_text);
2717 cdev->private->qdio_data = NULL;
2719 up(&irq_ptr->setting_up_sema);
2721 qdio_release_irq_memory(irq_ptr);
2722 module_put(THIS_MODULE);
2727 qdio_allocate_do_dbf(struct qdio_initialize *init_data)
2729 char dbf_text[20]; /* if a printf printed out more than 8 chars */
2731 sprintf(dbf_text,"qfmt:%x",init_data->q_format);
2732 QDIO_DBF_TEXT0(0,setup,dbf_text);
2733 QDIO_DBF_HEX0(0,setup,init_data->adapter_name,8);
2734 sprintf(dbf_text,"qpff%4x",init_data->qib_param_field_format);
2735 QDIO_DBF_TEXT0(0,setup,dbf_text);
2736 QDIO_DBF_HEX0(0,setup,&init_data->qib_param_field,sizeof(char*));
2737 QDIO_DBF_HEX0(0,setup,&init_data->input_slib_elements,sizeof(long*));
2738 QDIO_DBF_HEX0(0,setup,&init_data->output_slib_elements,sizeof(long*));
2739 sprintf(dbf_text,"miit%4x",init_data->min_input_threshold);
2740 QDIO_DBF_TEXT0(0,setup,dbf_text);
2741 sprintf(dbf_text,"mait%4x",init_data->max_input_threshold);
2742 QDIO_DBF_TEXT0(0,setup,dbf_text);
2743 sprintf(dbf_text,"miot%4x",init_data->min_output_threshold);
2744 QDIO_DBF_TEXT0(0,setup,dbf_text);
2745 sprintf(dbf_text,"maot%4x",init_data->max_output_threshold);
2746 QDIO_DBF_TEXT0(0,setup,dbf_text);
2747 sprintf(dbf_text,"niq:%4x",init_data->no_input_qs);
2748 QDIO_DBF_TEXT0(0,setup,dbf_text);
2749 sprintf(dbf_text,"noq:%4x",init_data->no_output_qs);
2750 QDIO_DBF_TEXT0(0,setup,dbf_text);
2751 QDIO_DBF_HEX0(0,setup,&init_data->input_handler,sizeof(void*));
2752 QDIO_DBF_HEX0(0,setup,&init_data->output_handler,sizeof(void*));
2753 QDIO_DBF_HEX0(0,setup,&init_data->int_parm,sizeof(long));
2754 QDIO_DBF_HEX0(0,setup,&init_data->flags,sizeof(long));
2755 QDIO_DBF_HEX0(0,setup,&init_data->input_sbal_addr_array,sizeof(void*));
2756 QDIO_DBF_HEX0(0,setup,&init_data->output_sbal_addr_array,sizeof(void*));
2760 qdio_allocate_fill_input_desc(struct qdio_irq *irq_ptr, int i, int iqfmt)
2762 irq_ptr->input_qs[i]->is_iqdio_q = iqfmt;
2763 irq_ptr->input_qs[i]->is_thinint_q = irq_ptr->is_thinint_irq;
2765 irq_ptr->qdr->qdf0[i].sliba=(unsigned long)(irq_ptr->input_qs[i]->slib);
2767 irq_ptr->qdr->qdf0[i].sla=(unsigned long)(irq_ptr->input_qs[i]->sl);
2769 irq_ptr->qdr->qdf0[i].slsba=
2770 (unsigned long)(&irq_ptr->input_qs[i]->slsb.acc.val[0]);
2772 irq_ptr->qdr->qdf0[i].akey=QDIO_STORAGE_KEY;
2773 irq_ptr->qdr->qdf0[i].bkey=QDIO_STORAGE_KEY;
2774 irq_ptr->qdr->qdf0[i].ckey=QDIO_STORAGE_KEY;
2775 irq_ptr->qdr->qdf0[i].dkey=QDIO_STORAGE_KEY;
2779 qdio_allocate_fill_output_desc(struct qdio_irq *irq_ptr, int i,
2782 irq_ptr->output_qs[i]->is_iqdio_q = iqfmt;
2783 irq_ptr->output_qs[i]->is_thinint_q = irq_ptr->is_thinint_irq;
2785 irq_ptr->qdr->qdf0[i+j].sliba=(unsigned long)(irq_ptr->output_qs[i]->slib);
2787 irq_ptr->qdr->qdf0[i+j].sla=(unsigned long)(irq_ptr->output_qs[i]->sl);
2789 irq_ptr->qdr->qdf0[i+j].slsba=
2790 (unsigned long)(&irq_ptr->output_qs[i]->slsb.acc.val[0]);
2792 irq_ptr->qdr->qdf0[i+j].akey=QDIO_STORAGE_KEY;
2793 irq_ptr->qdr->qdf0[i+j].bkey=QDIO_STORAGE_KEY;
2794 irq_ptr->qdr->qdf0[i+j].ckey=QDIO_STORAGE_KEY;
2795 irq_ptr->qdr->qdf0[i+j].dkey=QDIO_STORAGE_KEY;
2800 qdio_initialize_set_siga_flags_input(struct qdio_irq *irq_ptr)
2804 for (i=0;i<irq_ptr->no_input_qs;i++) {
2805 irq_ptr->input_qs[i]->siga_sync=
2806 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY;
2807 irq_ptr->input_qs[i]->siga_in=
2808 irq_ptr->qdioac&CHSC_FLAG_SIGA_INPUT_NECESSARY;
2809 irq_ptr->input_qs[i]->siga_out=
2810 irq_ptr->qdioac&CHSC_FLAG_SIGA_OUTPUT_NECESSARY;
2811 irq_ptr->input_qs[i]->siga_sync_done_on_thinints=
2812 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS;
2813 irq_ptr->input_qs[i]->hydra_gives_outbound_pcis=
2814 irq_ptr->hydra_gives_outbound_pcis;
2815 irq_ptr->input_qs[i]->siga_sync_done_on_outb_tis=
2817 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2818 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS))==
2819 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2820 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS));
2826 qdio_initialize_set_siga_flags_output(struct qdio_irq *irq_ptr)
2830 for (i=0;i<irq_ptr->no_output_qs;i++) {
2831 irq_ptr->output_qs[i]->siga_sync=
2832 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY;
2833 irq_ptr->output_qs[i]->siga_in=
2834 irq_ptr->qdioac&CHSC_FLAG_SIGA_INPUT_NECESSARY;
2835 irq_ptr->output_qs[i]->siga_out=
2836 irq_ptr->qdioac&CHSC_FLAG_SIGA_OUTPUT_NECESSARY;
2837 irq_ptr->output_qs[i]->siga_sync_done_on_thinints=
2838 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS;
2839 irq_ptr->output_qs[i]->hydra_gives_outbound_pcis=
2840 irq_ptr->hydra_gives_outbound_pcis;
2841 irq_ptr->output_qs[i]->siga_sync_done_on_outb_tis=
2843 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2844 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS))==
2845 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2846 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS));
2852 qdio_establish_irq_check_for_errors(struct ccw_device *cdev, int cstat,
2856 struct qdio_irq *irq_ptr;
2858 irq_ptr = cdev->private->qdio_data;
2860 if (cstat || (dstat & ~(DEV_STAT_CHN_END|DEV_STAT_DEV_END))) {
2861 sprintf(dbf_text,"ick1%4x",irq_ptr->schid.sch_no);
2862 QDIO_DBF_TEXT2(1,trace,dbf_text);
2863 QDIO_DBF_HEX2(0,trace,&dstat,sizeof(int));
2864 QDIO_DBF_HEX2(0,trace,&cstat,sizeof(int));
2865 QDIO_PRINT_ERR("received check condition on establish " \
2866 "queues on irq 0.%x.%x (cs=x%x, ds=x%x).\n",
2867 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
2869 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ERR);
2872 if (!(dstat & DEV_STAT_DEV_END)) {
2873 QDIO_DBF_TEXT2(1,setup,"eq:no de");
2874 QDIO_DBF_HEX2(0,setup,&dstat, sizeof(dstat));
2875 QDIO_DBF_HEX2(0,setup,&cstat, sizeof(cstat));
2876 QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: didn't get "
2877 "device end: dstat=%02x, cstat=%02x\n",
2878 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
2880 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2884 if (dstat & ~(DEV_STAT_CHN_END|DEV_STAT_DEV_END)) {
2885 QDIO_DBF_TEXT2(1,setup,"eq:badio");
2886 QDIO_DBF_HEX2(0,setup,&dstat, sizeof(dstat));
2887 QDIO_DBF_HEX2(0,setup,&cstat, sizeof(cstat));
2888 QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: got "
2889 "the following devstat: dstat=%02x, "
2890 "cstat=%02x\n", irq_ptr->schid.ssid,
2891 irq_ptr->schid.sch_no, dstat, cstat);
2892 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2899 qdio_establish_handle_irq(struct ccw_device *cdev, int cstat, int dstat)
2901 struct qdio_irq *irq_ptr;
2904 irq_ptr = cdev->private->qdio_data;
2906 sprintf(dbf_text,"qehi%4x",cdev->private->schid.sch_no);
2907 QDIO_DBF_TEXT0(0,setup,dbf_text);
2908 QDIO_DBF_TEXT0(0,trace,dbf_text);
2910 if (qdio_establish_irq_check_for_errors(cdev, cstat, dstat)) {
2911 ccw_device_set_timeout(cdev, 0);
2915 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ESTABLISHED);
2916 ccw_device_set_timeout(cdev, 0);
2920 qdio_initialize(struct qdio_initialize *init_data)
2925 sprintf(dbf_text,"qini%4x",init_data->cdev->private->schid.sch_no);
2926 QDIO_DBF_TEXT0(0,setup,dbf_text);
2927 QDIO_DBF_TEXT0(0,trace,dbf_text);
2929 rc = qdio_allocate(init_data);
2931 rc = qdio_establish(init_data);
2933 qdio_free(init_data->cdev);
2941 qdio_allocate(struct qdio_initialize *init_data)
2943 struct qdio_irq *irq_ptr;
2946 sprintf(dbf_text,"qalc%4x",init_data->cdev->private->schid.sch_no);
2947 QDIO_DBF_TEXT0(0,setup,dbf_text);
2948 QDIO_DBF_TEXT0(0,trace,dbf_text);
2949 if ( (init_data->no_input_qs>QDIO_MAX_QUEUES_PER_IRQ) ||
2950 (init_data->no_output_qs>QDIO_MAX_QUEUES_PER_IRQ) ||
2951 ((init_data->no_input_qs) && (!init_data->input_handler)) ||
2952 ((init_data->no_output_qs) && (!init_data->output_handler)) )
2955 if (!init_data->input_sbal_addr_array)
2958 if (!init_data->output_sbal_addr_array)
2961 qdio_allocate_do_dbf(init_data);
2964 irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
2966 QDIO_DBF_TEXT0(0,setup,"irq_ptr:");
2967 QDIO_DBF_HEX0(0,setup,&irq_ptr,sizeof(void*));
2970 QDIO_PRINT_ERR("allocation of irq_ptr failed!\n");
2974 init_MUTEX(&irq_ptr->setting_up_sema);
2976 /* QDR must be in DMA area since CCW data address is only 32 bit */
2977 irq_ptr->qdr = (struct qdr *) __get_free_page(GFP_KERNEL | GFP_DMA);
2978 if (!(irq_ptr->qdr)) {
2979 free_page((unsigned long) irq_ptr);
2980 QDIO_PRINT_ERR("allocation of irq_ptr->qdr failed!\n");
2983 QDIO_DBF_TEXT0(0,setup,"qdr:");
2984 QDIO_DBF_HEX0(0,setup,&irq_ptr->qdr,sizeof(void*));
2986 if (qdio_alloc_qs(irq_ptr,
2987 init_data->no_input_qs,
2988 init_data->no_output_qs)) {
2989 QDIO_PRINT_ERR("queue allocation failed!\n");
2990 qdio_release_irq_memory(irq_ptr);
2994 init_data->cdev->private->qdio_data = irq_ptr;
2996 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_INACTIVE);
3001 static int qdio_fill_irq(struct qdio_initialize *init_data)
3007 struct qdio_irq *irq_ptr;
3009 irq_ptr = init_data->cdev->private->qdio_data;
3011 memset(irq_ptr,0,((char*)&irq_ptr->qdr)-((char*)irq_ptr));
3013 /* wipes qib.ac, required by ar7063 */
3014 memset(irq_ptr->qdr,0,sizeof(struct qdr));
3016 irq_ptr->int_parm=init_data->int_parm;
3018 irq_ptr->schid = ccw_device_get_subchannel_id(init_data->cdev);
3019 irq_ptr->no_input_qs=init_data->no_input_qs;
3020 irq_ptr->no_output_qs=init_data->no_output_qs;
3022 if (init_data->q_format==QDIO_IQDIO_QFMT) {
3023 irq_ptr->is_iqdio_irq=1;
3024 irq_ptr->is_thinint_irq=1;
3026 irq_ptr->is_iqdio_irq=0;
3027 irq_ptr->is_thinint_irq=hydra_thinints;
3029 sprintf(dbf_text,"is_i_t%1x%1x",
3030 irq_ptr->is_iqdio_irq,irq_ptr->is_thinint_irq);
3031 QDIO_DBF_TEXT2(0,setup,dbf_text);
3033 if (irq_ptr->is_thinint_irq) {
3034 irq_ptr->dev_st_chg_ind = qdio_get_indicator();
3035 QDIO_DBF_HEX1(0,setup,&irq_ptr->dev_st_chg_ind,sizeof(void*));
3036 if (!irq_ptr->dev_st_chg_ind) {
3037 QDIO_PRINT_WARN("no indicator location available " \
3038 "for irq 0.%x.%x\n",
3039 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
3040 qdio_release_irq_memory(irq_ptr);
3046 irq_ptr->equeue.cmd=DEFAULT_ESTABLISH_QS_CMD;
3047 irq_ptr->equeue.count=DEFAULT_ESTABLISH_QS_COUNT;
3048 irq_ptr->aqueue.cmd=DEFAULT_ACTIVATE_QS_CMD;
3049 irq_ptr->aqueue.count=DEFAULT_ACTIVATE_QS_COUNT;
3051 qdio_fill_qs(irq_ptr, init_data->cdev,
3052 init_data->no_input_qs,
3053 init_data->no_output_qs,
3054 init_data->input_handler,
3055 init_data->output_handler,init_data->int_parm,
3056 init_data->q_format,init_data->flags,
3057 init_data->input_sbal_addr_array,
3058 init_data->output_sbal_addr_array);
3060 if (!try_module_get(THIS_MODULE)) {
3061 QDIO_PRINT_CRIT("try_module_get() failed!\n");
3062 qdio_release_irq_memory(irq_ptr);
3066 qdio_fill_thresholds(irq_ptr,init_data->no_input_qs,
3067 init_data->no_output_qs,
3068 init_data->min_input_threshold,
3069 init_data->max_input_threshold,
3070 init_data->min_output_threshold,
3071 init_data->max_output_threshold);
3074 irq_ptr->qdr->qfmt=init_data->q_format;
3075 irq_ptr->qdr->iqdcnt=init_data->no_input_qs;
3076 irq_ptr->qdr->oqdcnt=init_data->no_output_qs;
3077 irq_ptr->qdr->iqdsz=sizeof(struct qdesfmt0)/4; /* size in words */
3078 irq_ptr->qdr->oqdsz=sizeof(struct qdesfmt0)/4;
3080 irq_ptr->qdr->qiba=(unsigned long)&irq_ptr->qib;
3081 irq_ptr->qdr->qkey=QDIO_STORAGE_KEY;
3084 irq_ptr->is_qebsm = is_passthrough;
3085 if (irq_ptr->is_qebsm)
3086 irq_ptr->qib.rflags |= QIB_RFLAGS_ENABLE_QEBSM;
3088 irq_ptr->qib.qfmt=init_data->q_format;
3089 if (init_data->no_input_qs)
3090 irq_ptr->qib.isliba=(unsigned long)(irq_ptr->input_qs[0]->slib);
3091 if (init_data->no_output_qs)
3092 irq_ptr->qib.osliba=(unsigned long)(irq_ptr->output_qs[0]->slib);
3093 memcpy(irq_ptr->qib.ebcnam,init_data->adapter_name,8);
3095 qdio_set_impl_params(irq_ptr,init_data->qib_param_field_format,
3096 init_data->qib_param_field,
3097 init_data->no_input_qs,
3098 init_data->no_output_qs,
3099 init_data->input_slib_elements,
3100 init_data->output_slib_elements);
3102 /* first input descriptors, then output descriptors */
3103 is_iqdio = (init_data->q_format == QDIO_IQDIO_QFMT) ? 1 : 0;
3104 for (i=0;i<init_data->no_input_qs;i++)
3105 qdio_allocate_fill_input_desc(irq_ptr, i, is_iqdio);
3107 for (i=0;i<init_data->no_output_qs;i++)
3108 qdio_allocate_fill_output_desc(irq_ptr, i,
3109 init_data->no_input_qs,
3112 /* qdr, qib, sls, slsbs, slibs, sbales filled. */
3114 /* get qdio commands */
3115 ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_EQUEUE);
3117 QDIO_DBF_TEXT2(1,setup,"no eq");
3118 QDIO_PRINT_INFO("No equeue CIW found for QDIO commands. "
3119 "Trying to use default.\n");
3121 irq_ptr->equeue = *ciw;
3122 ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_AQUEUE);
3124 QDIO_DBF_TEXT2(1,setup,"no aq");
3125 QDIO_PRINT_INFO("No aqueue CIW found for QDIO commands. "
3126 "Trying to use default.\n");
3128 irq_ptr->aqueue = *ciw;
3130 /* Set new interrupt handler. */
3131 irq_ptr->original_int_handler = init_data->cdev->handler;
3132 init_data->cdev->handler = qdio_handler;
3138 qdio_establish(struct qdio_initialize *init_data)
3140 struct qdio_irq *irq_ptr;
3141 unsigned long saveflags;
3142 int result, result2;
3143 struct ccw_device *cdev;
3146 cdev=init_data->cdev;
3147 irq_ptr = cdev->private->qdio_data;
3151 if (cdev->private->state != DEV_STATE_ONLINE)
3154 down(&irq_ptr->setting_up_sema);
3156 qdio_fill_irq(init_data);
3158 /* the thinint CHSC stuff */
3159 if (irq_ptr->is_thinint_irq) {
3161 result = tiqdio_set_subchannel_ind(irq_ptr,0);
3163 up(&irq_ptr->setting_up_sema);
3164 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
3167 tiqdio_set_delay_target(irq_ptr,TIQDIO_DELAY_TARGET);
3170 sprintf(dbf_text,"qest%4x",cdev->private->schid.sch_no);
3171 QDIO_DBF_TEXT0(0,setup,dbf_text);
3172 QDIO_DBF_TEXT0(0,trace,dbf_text);
3175 irq_ptr->ccw.cmd_code=irq_ptr->equeue.cmd;
3176 irq_ptr->ccw.flags=CCW_FLAG_SLI;
3177 irq_ptr->ccw.count=irq_ptr->equeue.count;
3178 irq_ptr->ccw.cda=QDIO_GET_ADDR(irq_ptr->qdr);
3180 spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags);
3182 ccw_device_set_options_mask(cdev, 0);
3183 result = ccw_device_start(cdev, &irq_ptr->ccw,
3184 QDIO_DOING_ESTABLISH, 0, 0);
3186 result2 = ccw_device_start(cdev, &irq_ptr->ccw,
3187 QDIO_DOING_ESTABLISH, 0, 0);
3188 sprintf(dbf_text,"eq:io%4x",result);
3189 QDIO_DBF_TEXT2(1,setup,dbf_text);
3191 sprintf(dbf_text,"eq:io%4x",result);
3192 QDIO_DBF_TEXT2(1,setup,dbf_text);
3194 QDIO_PRINT_WARN("establish queues on irq 0.%x.%04x: do_IO " \
3195 "returned %i, next try returned %i\n",
3196 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
3200 ccw_device_set_timeout(cdev, 0);
3203 spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags);
3206 up(&irq_ptr->setting_up_sema);
3207 qdio_shutdown(cdev,QDIO_FLAG_CLEANUP_USING_CLEAR);
3211 wait_event_interruptible_timeout(cdev->private->wait_q,
3212 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
3213 irq_ptr->state == QDIO_IRQ_STATE_ERR,
3214 QDIO_ESTABLISH_TIMEOUT);
3216 if (irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED)
3219 up(&irq_ptr->setting_up_sema);
3220 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
3224 qdio_get_ssqd_siga(irq_ptr);
3225 /* if this gets set once, we're running under VM and can omit SVSes */
3226 if (irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY)
3229 sprintf(dbf_text,"qdioac%2x",irq_ptr->qdioac);
3230 QDIO_DBF_TEXT2(0,setup,dbf_text);
3232 sprintf(dbf_text,"qib ac%2x",irq_ptr->qib.ac);
3233 QDIO_DBF_TEXT2(0,setup,dbf_text);
3235 irq_ptr->hydra_gives_outbound_pcis=
3236 irq_ptr->qib.ac&QIB_AC_OUTBOUND_PCI_SUPPORTED;
3237 irq_ptr->sync_done_on_outb_pcis=
3238 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS;
3240 qdio_initialize_set_siga_flags_input(irq_ptr);
3241 qdio_initialize_set_siga_flags_output(irq_ptr);
3243 up(&irq_ptr->setting_up_sema);
3250 qdio_activate(struct ccw_device *cdev, int flags)
3252 struct qdio_irq *irq_ptr;
3253 int i,result=0,result2;
3254 unsigned long saveflags;
3255 char dbf_text[20]; /* see qdio_initialize */
3257 irq_ptr = cdev->private->qdio_data;
3261 if (cdev->private->state != DEV_STATE_ONLINE)
3264 down(&irq_ptr->setting_up_sema);
3265 if (irq_ptr->state==QDIO_IRQ_STATE_INACTIVE) {
3270 sprintf(dbf_text,"qact%4x", irq_ptr->schid.sch_no);
3271 QDIO_DBF_TEXT2(0,setup,dbf_text);
3272 QDIO_DBF_TEXT2(0,trace,dbf_text);
3275 irq_ptr->ccw.cmd_code=irq_ptr->aqueue.cmd;
3276 irq_ptr->ccw.flags=CCW_FLAG_SLI;
3277 irq_ptr->ccw.count=irq_ptr->aqueue.count;
3278 irq_ptr->ccw.cda=QDIO_GET_ADDR(0);
3280 spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags);
3282 ccw_device_set_timeout(cdev, 0);
3283 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
3284 result=ccw_device_start(cdev,&irq_ptr->ccw,QDIO_DOING_ACTIVATE,
3285 0, DOIO_DENY_PREFETCH);
3287 result2=ccw_device_start(cdev,&irq_ptr->ccw,
3288 QDIO_DOING_ACTIVATE,0,0);
3289 sprintf(dbf_text,"aq:io%4x",result);
3290 QDIO_DBF_TEXT2(1,setup,dbf_text);
3292 sprintf(dbf_text,"aq:io%4x",result);
3293 QDIO_DBF_TEXT2(1,setup,dbf_text);
3295 QDIO_PRINT_WARN("activate queues on irq 0.%x.%04x: do_IO " \
3296 "returned %i, next try returned %i\n",
3297 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
3302 spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags);
3306 for (i=0;i<irq_ptr->no_input_qs;i++) {
3307 if (irq_ptr->is_thinint_irq) {
3309 * that way we know, that, if we will get interrupted
3310 * by tiqdio_inbound_processing, qdio_unmark_q will
3313 qdio_reserve_q(irq_ptr->input_qs[i]);
3314 qdio_mark_tiq(irq_ptr->input_qs[i]);
3315 qdio_release_q(irq_ptr->input_qs[i]);
3319 if (flags&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT) {
3320 for (i=0;i<irq_ptr->no_input_qs;i++) {
3321 irq_ptr->input_qs[i]->is_input_q|=
3322 QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT;
3326 msleep(QDIO_ACTIVATE_TIMEOUT);
3327 switch (irq_ptr->state) {
3328 case QDIO_IRQ_STATE_STOPPED:
3329 case QDIO_IRQ_STATE_ERR:
3330 up(&irq_ptr->setting_up_sema);
3331 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
3332 down(&irq_ptr->setting_up_sema);
3336 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
3340 up(&irq_ptr->setting_up_sema);
3345 /* buffers filled forwards again to make Rick happy */
3347 qdio_do_qdio_fill_input(struct qdio_q *q, unsigned int qidx,
3348 unsigned int count, struct qdio_buffer *buffers)
3350 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
3353 qidx &= (QDIO_MAX_BUFFERS_PER_Q - 1);
3354 if (irq->is_qebsm) {
3356 tmp = set_slsb(q, &qidx, SLSB_CU_INPUT_EMPTY, &count);
3363 set_slsb(q, &qidx, SLSB_CU_INPUT_EMPTY, &count);
3366 qidx = (qidx + 1) & (QDIO_MAX_BUFFERS_PER_Q - 1);
3371 qdio_do_qdio_fill_output(struct qdio_q *q, unsigned int qidx,
3372 unsigned int count, struct qdio_buffer *buffers)
3374 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
3377 qidx &= (QDIO_MAX_BUFFERS_PER_Q - 1);
3378 if (irq->is_qebsm) {
3380 tmp = set_slsb(q, &qidx, SLSB_CU_OUTPUT_PRIMED, &count);
3388 set_slsb(q, &qidx, SLSB_CU_OUTPUT_PRIMED, &count);
3391 qidx = (qidx + 1) & (QDIO_MAX_BUFFERS_PER_Q - 1);
3396 do_qdio_handle_inbound(struct qdio_q *q, unsigned int callflags,
3397 unsigned int qidx, unsigned int count,
3398 struct qdio_buffer *buffers)
3402 /* This is the inbound handling of queues */
3403 used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count;
3405 qdio_do_qdio_fill_input(q,qidx,count,buffers);
3407 if ((used_elements+count==QDIO_MAX_BUFFERS_PER_Q)&&
3408 (callflags&QDIO_FLAG_UNDER_INTERRUPT))
3409 atomic_xchg(&q->polling,0);
3413 if (callflags&QDIO_FLAG_DONT_SIGA)
3418 result=qdio_siga_input(q);
3421 q->error_status_flags|=
3422 QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR;
3423 q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR;
3424 q->siga_error=result;
3432 do_qdio_handle_outbound(struct qdio_q *q, unsigned int callflags,
3433 unsigned int qidx, unsigned int count,
3434 struct qdio_buffer *buffers)
3437 unsigned int cnt, start_buf;
3438 unsigned char state = 0;
3439 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
3441 /* This is the outbound handling of queues */
3442 qdio_do_qdio_fill_output(q,qidx,count,buffers);
3444 used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count;
3446 if (callflags&QDIO_FLAG_DONT_SIGA) {
3447 qdio_perf_stat_inc(&perf_stats.outbound_cnt);
3450 if (callflags & QDIO_FLAG_PCI_OUT)
3454 if (q->is_iqdio_q) {
3455 /* one siga for every sbal */
3457 qdio_kick_outbound_q(q);
3459 __qdio_outbound_processing(q);
3461 /* under VM, we do a SIGA sync unconditionally */
3465 * w/o shadow queues (else branch of
3466 * SYNC_MEMORY :-/ ), we try to
3467 * fast-requeue buffers
3469 if (irq->is_qebsm) {
3471 start_buf = ((qidx+QDIO_MAX_BUFFERS_PER_Q-1) &
3472 (QDIO_MAX_BUFFERS_PER_Q-1));
3473 qdio_do_eqbs(q, &state, &start_buf, &cnt);
3475 state = q->slsb.acc.val[(qidx+QDIO_MAX_BUFFERS_PER_Q-1)
3476 &(QDIO_MAX_BUFFERS_PER_Q-1) ];
3477 if (state != SLSB_CU_OUTPUT_PRIMED) {
3478 qdio_kick_outbound_q(q);
3480 QDIO_DBF_TEXT3(0,trace, "fast-req");
3481 qdio_perf_stat_inc(&perf_stats.fast_reqs);
3485 * only marking the q could take too long,
3486 * the upper layer module could do a lot of
3487 * traffic in that time
3489 __qdio_outbound_processing(q);
3492 qdio_perf_stat_inc(&perf_stats.outbound_cnt);
3495 /* count must be 1 in iqdio */
3497 do_QDIO(struct ccw_device *cdev,unsigned int callflags,
3498 unsigned int queue_number, unsigned int qidx,
3499 unsigned int count,struct qdio_buffer *buffers)
3501 struct qdio_irq *irq_ptr;
3502 #ifdef CONFIG_QDIO_DEBUG
3505 sprintf(dbf_text,"doQD%04x",cdev->private->schid.sch_no);
3506 QDIO_DBF_TEXT3(0,trace,dbf_text);
3507 #endif /* CONFIG_QDIO_DEBUG */
3509 if ( (qidx>QDIO_MAX_BUFFERS_PER_Q) ||
3510 (count>QDIO_MAX_BUFFERS_PER_Q) ||
3511 (queue_number>QDIO_MAX_QUEUES_PER_IRQ) )
3517 irq_ptr = cdev->private->qdio_data;
3521 #ifdef CONFIG_QDIO_DEBUG
3522 if (callflags&QDIO_FLAG_SYNC_INPUT)
3523 QDIO_DBF_HEX3(0,trace,&irq_ptr->input_qs[queue_number],
3526 QDIO_DBF_HEX3(0,trace,&irq_ptr->output_qs[queue_number],
3528 sprintf(dbf_text,"flag%04x",callflags);
3529 QDIO_DBF_TEXT3(0,trace,dbf_text);
3530 sprintf(dbf_text,"qi%02xct%02x",qidx,count);
3531 QDIO_DBF_TEXT3(0,trace,dbf_text);
3532 #endif /* CONFIG_QDIO_DEBUG */
3534 if (irq_ptr->state!=QDIO_IRQ_STATE_ACTIVE)
3537 if (callflags&QDIO_FLAG_SYNC_INPUT)
3538 do_qdio_handle_inbound(irq_ptr->input_qs[queue_number],
3539 callflags, qidx, count, buffers);
3540 else if (callflags&QDIO_FLAG_SYNC_OUTPUT)
3541 do_qdio_handle_outbound(irq_ptr->output_qs[queue_number],
3542 callflags, qidx, count, buffers);
3544 QDIO_DBF_TEXT3(1,trace,"doQD:inv");
3551 qdio_perf_procfile_read(char *buffer, char **buffer_location, off_t offset,
3552 int buffer_length, int *eof, void *data)
3556 /* we are always called with buffer_length=4k, so we all
3557 deliver on the first read */
3561 #define _OUTP_IT(x...) c+=sprintf(buffer+c,x)
3563 _OUTP_IT("Number of tasklet runs (total) : %li\n",
3564 (long)atomic64_read(&perf_stats.tl_runs));
3565 _OUTP_IT("Inbound tasklet runs tried/retried : %li/%li\n",
3566 (long)atomic64_read(&perf_stats.inbound_tl_runs),
3567 (long)atomic64_read(&perf_stats.inbound_tl_runs_resched));
3568 _OUTP_IT("Inbound-thin tasklet runs tried/retried : %li/%li\n",
3569 (long)atomic64_read(&perf_stats.inbound_thin_tl_runs),
3570 (long)atomic64_read(&perf_stats.inbound_thin_tl_runs_resched));
3571 _OUTP_IT("Outbound tasklet runs tried/retried : %li/%li\n",
3572 (long)atomic64_read(&perf_stats.outbound_tl_runs),
3573 (long)atomic64_read(&perf_stats.outbound_tl_runs_resched));
3575 _OUTP_IT("Number of SIGA sync's issued : %li\n",
3576 (long)atomic64_read(&perf_stats.siga_syncs));
3577 _OUTP_IT("Number of SIGA in's issued : %li\n",
3578 (long)atomic64_read(&perf_stats.siga_ins));
3579 _OUTP_IT("Number of SIGA out's issued : %li\n",
3580 (long)atomic64_read(&perf_stats.siga_outs));
3581 _OUTP_IT("Number of PCIs caught : %li\n",
3582 (long)atomic64_read(&perf_stats.pcis));
3583 _OUTP_IT("Number of adapter interrupts caught : %li\n",
3584 (long)atomic64_read(&perf_stats.thinints));
3585 _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %li\n",
3586 (long)atomic64_read(&perf_stats.fast_reqs));
3588 _OUTP_IT("Number of inbound transfers : %li\n",
3589 (long)atomic64_read(&perf_stats.inbound_cnt));
3590 _OUTP_IT("Number of do_QDIOs outbound : %li\n",
3591 (long)atomic64_read(&perf_stats.outbound_cnt));
3592 #else /* CONFIG_64BIT */
3593 _OUTP_IT("Number of tasklet runs (total) : %i\n",
3594 atomic_read(&perf_stats.tl_runs));
3595 _OUTP_IT("Inbound tasklet runs tried/retried : %i/%i\n",
3596 atomic_read(&perf_stats.inbound_tl_runs),
3597 atomic_read(&perf_stats.inbound_tl_runs_resched));
3598 _OUTP_IT("Inbound-thin tasklet runs tried/retried : %i/%i\n",
3599 atomic_read(&perf_stats.inbound_thin_tl_runs),
3600 atomic_read(&perf_stats.inbound_thin_tl_runs_resched));
3601 _OUTP_IT("Outbound tasklet runs tried/retried : %i/%i\n",
3602 atomic_read(&perf_stats.outbound_tl_runs),
3603 atomic_read(&perf_stats.outbound_tl_runs_resched));
3605 _OUTP_IT("Number of SIGA sync's issued : %i\n",
3606 atomic_read(&perf_stats.siga_syncs));
3607 _OUTP_IT("Number of SIGA in's issued : %i\n",
3608 atomic_read(&perf_stats.siga_ins));
3609 _OUTP_IT("Number of SIGA out's issued : %i\n",
3610 atomic_read(&perf_stats.siga_outs));
3611 _OUTP_IT("Number of PCIs caught : %i\n",
3612 atomic_read(&perf_stats.pcis));
3613 _OUTP_IT("Number of adapter interrupts caught : %i\n",
3614 atomic_read(&perf_stats.thinints));
3615 _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %i\n",
3616 atomic_read(&perf_stats.fast_reqs));
3618 _OUTP_IT("Number of inbound transfers : %i\n",
3619 atomic_read(&perf_stats.inbound_cnt));
3620 _OUTP_IT("Number of do_QDIOs outbound : %i\n",
3621 atomic_read(&perf_stats.outbound_cnt));
3622 #endif /* CONFIG_64BIT */
3628 static struct proc_dir_entry *qdio_perf_proc_file;
3631 qdio_add_procfs_entry(void)
3633 proc_perf_file_registration=0;
3634 qdio_perf_proc_file=create_proc_entry(QDIO_PERF,
3636 if (qdio_perf_proc_file) {
3637 qdio_perf_proc_file->read_proc=&qdio_perf_procfile_read;
3638 } else proc_perf_file_registration=-1;
3640 if (proc_perf_file_registration)
3641 QDIO_PRINT_WARN("was not able to register perf. " \
3642 "proc-file (%i).\n",
3643 proc_perf_file_registration);
3647 qdio_remove_procfs_entry(void)
3649 if (!proc_perf_file_registration) /* means if it went ok earlier */
3650 remove_proc_entry(QDIO_PERF,NULL);
3654 * attributes in sysfs
3655 *****************************************************************************/
3658 qdio_performance_stats_show(struct bus_type *bus, char *buf)
3660 return sprintf(buf, "%i\n", qdio_performance_stats ? 1 : 0);
3664 qdio_performance_stats_store(struct bus_type *bus, const char *buf, size_t count)
3669 i = simple_strtoul(buf, &tmp, 16);
3670 if ((i == 0) || (i == 1)) {
3671 if (i == qdio_performance_stats)
3673 qdio_performance_stats = i;
3675 /* reset perf. stat. info */
3677 atomic64_set(&perf_stats.tl_runs, 0);
3678 atomic64_set(&perf_stats.outbound_tl_runs, 0);
3679 atomic64_set(&perf_stats.inbound_tl_runs, 0);
3680 atomic64_set(&perf_stats.inbound_tl_runs_resched, 0);
3681 atomic64_set(&perf_stats.inbound_thin_tl_runs, 0);
3682 atomic64_set(&perf_stats.inbound_thin_tl_runs_resched,
3684 atomic64_set(&perf_stats.siga_outs, 0);
3685 atomic64_set(&perf_stats.siga_ins, 0);
3686 atomic64_set(&perf_stats.siga_syncs, 0);
3687 atomic64_set(&perf_stats.pcis, 0);
3688 atomic64_set(&perf_stats.thinints, 0);
3689 atomic64_set(&perf_stats.fast_reqs, 0);
3690 atomic64_set(&perf_stats.outbound_cnt, 0);
3691 atomic64_set(&perf_stats.inbound_cnt, 0);
3692 #else /* CONFIG_64BIT */
3693 atomic_set(&perf_stats.tl_runs, 0);
3694 atomic_set(&perf_stats.outbound_tl_runs, 0);
3695 atomic_set(&perf_stats.inbound_tl_runs, 0);
3696 atomic_set(&perf_stats.inbound_tl_runs_resched, 0);
3697 atomic_set(&perf_stats.inbound_thin_tl_runs, 0);
3698 atomic_set(&perf_stats.inbound_thin_tl_runs_resched, 0);
3699 atomic_set(&perf_stats.siga_outs, 0);
3700 atomic_set(&perf_stats.siga_ins, 0);
3701 atomic_set(&perf_stats.siga_syncs, 0);
3702 atomic_set(&perf_stats.pcis, 0);
3703 atomic_set(&perf_stats.thinints, 0);
3704 atomic_set(&perf_stats.fast_reqs, 0);
3705 atomic_set(&perf_stats.outbound_cnt, 0);
3706 atomic_set(&perf_stats.inbound_cnt, 0);
3707 #endif /* CONFIG_64BIT */
3710 QDIO_PRINT_ERR("QDIO performance_stats: write 0 or 1 to this file!\n");
3716 static BUS_ATTR(qdio_performance_stats, 0644, qdio_performance_stats_show,
3717 qdio_performance_stats_store);
3720 tiqdio_register_thinints(void)
3725 s390_register_adapter_interrupt(&tiqdio_thinint_handler, NULL);
3726 if (IS_ERR(tiqdio_ind)) {
3727 sprintf(dbf_text, "regthn%lx", PTR_ERR(tiqdio_ind));
3728 QDIO_DBF_TEXT0(0,setup,dbf_text);
3729 QDIO_PRINT_ERR("failed to register adapter handler " \
3730 "(rc=%li).\nAdapter interrupts might " \
3731 "not work. Continuing.\n",
3732 PTR_ERR(tiqdio_ind));
3738 tiqdio_unregister_thinints(void)
3741 s390_unregister_adapter_interrupt(tiqdio_ind);
3745 qdio_get_qdio_memory(void)
3748 indicator_used[0]=1;
3750 for (i=1;i<INDICATORS_PER_CACHELINE;i++)
3751 indicator_used[i]=0;
3752 indicators = kzalloc(sizeof(__u32)*(INDICATORS_PER_CACHELINE),
3760 qdio_release_qdio_memory(void)
3766 qdio_unregister_dbf_views(void)
3769 debug_unregister(qdio_dbf_setup);
3771 debug_unregister(qdio_dbf_sbal);
3773 debug_unregister(qdio_dbf_sense);
3775 debug_unregister(qdio_dbf_trace);
3776 #ifdef CONFIG_QDIO_DEBUG
3777 if (qdio_dbf_slsb_out)
3778 debug_unregister(qdio_dbf_slsb_out);
3779 if (qdio_dbf_slsb_in)
3780 debug_unregister(qdio_dbf_slsb_in);
3781 #endif /* CONFIG_QDIO_DEBUG */
3785 qdio_register_dbf_views(void)
3787 qdio_dbf_setup=debug_register(QDIO_DBF_SETUP_NAME,
3788 QDIO_DBF_SETUP_PAGES,
3789 QDIO_DBF_SETUP_NR_AREAS,
3790 QDIO_DBF_SETUP_LEN);
3791 if (!qdio_dbf_setup)
3793 debug_register_view(qdio_dbf_setup,&debug_hex_ascii_view);
3794 debug_set_level(qdio_dbf_setup,QDIO_DBF_SETUP_LEVEL);
3796 qdio_dbf_sbal=debug_register(QDIO_DBF_SBAL_NAME,
3797 QDIO_DBF_SBAL_PAGES,
3798 QDIO_DBF_SBAL_NR_AREAS,
3803 debug_register_view(qdio_dbf_sbal,&debug_hex_ascii_view);
3804 debug_set_level(qdio_dbf_sbal,QDIO_DBF_SBAL_LEVEL);
3806 qdio_dbf_sense=debug_register(QDIO_DBF_SENSE_NAME,
3807 QDIO_DBF_SENSE_PAGES,
3808 QDIO_DBF_SENSE_NR_AREAS,
3809 QDIO_DBF_SENSE_LEN);
3810 if (!qdio_dbf_sense)
3813 debug_register_view(qdio_dbf_sense,&debug_hex_ascii_view);
3814 debug_set_level(qdio_dbf_sense,QDIO_DBF_SENSE_LEVEL);
3816 qdio_dbf_trace=debug_register(QDIO_DBF_TRACE_NAME,
3817 QDIO_DBF_TRACE_PAGES,
3818 QDIO_DBF_TRACE_NR_AREAS,
3819 QDIO_DBF_TRACE_LEN);
3820 if (!qdio_dbf_trace)
3823 debug_register_view(qdio_dbf_trace,&debug_hex_ascii_view);
3824 debug_set_level(qdio_dbf_trace,QDIO_DBF_TRACE_LEVEL);
3826 #ifdef CONFIG_QDIO_DEBUG
3827 qdio_dbf_slsb_out=debug_register(QDIO_DBF_SLSB_OUT_NAME,
3828 QDIO_DBF_SLSB_OUT_PAGES,
3829 QDIO_DBF_SLSB_OUT_NR_AREAS,
3830 QDIO_DBF_SLSB_OUT_LEN);
3831 if (!qdio_dbf_slsb_out)
3833 debug_register_view(qdio_dbf_slsb_out,&debug_hex_ascii_view);
3834 debug_set_level(qdio_dbf_slsb_out,QDIO_DBF_SLSB_OUT_LEVEL);
3836 qdio_dbf_slsb_in=debug_register(QDIO_DBF_SLSB_IN_NAME,
3837 QDIO_DBF_SLSB_IN_PAGES,
3838 QDIO_DBF_SLSB_IN_NR_AREAS,
3839 QDIO_DBF_SLSB_IN_LEN);
3840 if (!qdio_dbf_slsb_in)
3842 debug_register_view(qdio_dbf_slsb_in,&debug_hex_ascii_view);
3843 debug_set_level(qdio_dbf_slsb_in,QDIO_DBF_SLSB_IN_LEVEL);
3844 #endif /* CONFIG_QDIO_DEBUG */
3847 QDIO_PRINT_ERR("not enough memory for dbf.\n");
3848 qdio_unregister_dbf_views();
3852 static void *qdio_mempool_alloc(gfp_t gfp_mask, void *size)
3854 return (void *) get_zeroed_page(gfp_mask|GFP_DMA);
3857 static void qdio_mempool_free(void *element, void *size)
3859 free_page((unsigned long) element);
3868 printk("qdio: loading %s\n",version);
3870 res=qdio_get_qdio_memory();
3874 qdio_q_cache = kmem_cache_create("qdio_q", sizeof(struct qdio_q),
3876 if (!qdio_q_cache) {
3877 qdio_release_qdio_memory();
3881 res = qdio_register_dbf_views();
3883 kmem_cache_destroy(qdio_q_cache);
3884 qdio_release_qdio_memory();
3888 QDIO_DBF_TEXT0(0,setup,"initQDIO");
3889 res = bus_create_file(&ccw_bus_type, &bus_attr_qdio_performance_stats);
3891 memset((void*)&perf_stats,0,sizeof(perf_stats));
3892 QDIO_DBF_TEXT0(0,setup,"perfstat");
3894 QDIO_DBF_HEX0(0,setup,&ptr,sizeof(void*));
3896 qdio_add_procfs_entry();
3898 qdio_mempool_scssc = mempool_create(QDIO_MEMPOOL_SCSSC_ELEMENTS,
3900 qdio_mempool_free, NULL);
3902 if (tiqdio_check_chsc_availability())
3903 QDIO_PRINT_ERR("Not all CHSCs supported. Continuing.\n");
3905 tiqdio_register_thinints();
3913 tiqdio_unregister_thinints();
3914 qdio_remove_procfs_entry();
3915 qdio_release_qdio_memory();
3916 qdio_unregister_dbf_views();
3917 mempool_destroy(qdio_mempool_scssc);
3918 kmem_cache_destroy(qdio_q_cache);
3919 bus_remove_file(&ccw_bus_type, &bus_attr_qdio_performance_stats);
3920 printk("qdio: %s: module removed\n",version);
3923 module_init(init_QDIO);
3924 module_exit(cleanup_QDIO);
3926 EXPORT_SYMBOL(qdio_allocate);
3927 EXPORT_SYMBOL(qdio_establish);
3928 EXPORT_SYMBOL(qdio_initialize);
3929 EXPORT_SYMBOL(qdio_activate);
3930 EXPORT_SYMBOL(do_QDIO);
3931 EXPORT_SYMBOL(qdio_shutdown);
3932 EXPORT_SYMBOL(qdio_free);
3933 EXPORT_SYMBOL(qdio_cleanup);
3934 EXPORT_SYMBOL(qdio_synchronize);