3 * linux/drivers/s390/cio/qdio.c
5 * Linux for S/390 QDIO base support, Hipersocket base support
8 * Copyright 2000,2002 IBM Corporation
9 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
10 * 2.6 cio integration by Cornelia Huck <cornelia.huck@de.ibm.com>
12 * Restriction: only 63 iqdio subchannels would have its own indicator,
13 * after that, subsequent subchannels share one indicator
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <linux/module.h>
34 #include <linux/init.h>
36 #include <linux/slab.h>
37 #include <linux/kernel.h>
38 #include <linux/proc_fs.h>
39 #include <linux/timer.h>
40 #include <linux/mempool.h>
42 #include <asm/ccwdev.h>
44 #include <asm/atomic.h>
45 #include <asm/semaphore.h>
46 #include <asm/timex.h>
48 #include <asm/debug.h>
49 #include <asm/s390_rdev.h>
60 /****************** MODULE PARAMETER VARIABLES ********************/
61 MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>");
62 MODULE_DESCRIPTION("QDIO base support version 2, " \
63 "Copyright 2000 IBM Corporation");
64 MODULE_LICENSE("GPL");
66 /******************** HERE WE GO ***********************************/
68 static const char version[] = "QDIO base support version 2";
70 static int qdio_performance_stats = 0;
71 static int proc_perf_file_registration;
72 static 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 int register_thinint_result;
100 static void tiqdio_tl(unsigned long);
101 static DECLARE_TASKLET(tiqdio_tasklet,tiqdio_tl,0);
103 /* not a macro, as one of the arguments is atomic_read */
105 qdio_min(int a,int b)
113 /***************** SCRUBBER HELPER ROUTINES **********************/
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=1;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(struct qdio_q *q)
1029 __qdio_outbound_processing(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 (!q->siga_sync && !irq->is_qebsm)
1219 /* we'll check for more primed buffers in qeth_stop_polling */
1221 if (irq->is_qebsm) {
1223 start_buf = q->first_to_check;
1224 qdio_do_eqbs(q, &state, &start_buf, &count);
1226 state = q->slsb.acc.val[q->first_to_check];
1227 if (state != SLSB_P_INPUT_PRIMED)
1229 * nothing more to do, if next buffer is not PRIMED.
1230 * note that we did a SYNC_MEMORY before, that there
1231 * has been a sychnronization.
1232 * we will return 0 below, as there is nothing to do
1233 * (stop_polling not necessary, as we have not been
1234 * using the PROCESSING state
1239 * ok, the next input buffer is primed. that means, that device state
1240 * change indicator and adapter local summary are set, so we will find
1242 * we will return 0 below, as there is nothing to do, except scheduling
1243 * ourselves for the next time.
1245 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1251 qdio_is_inbound_q_done(struct qdio_q *q)
1254 unsigned int start_buf, count;
1255 unsigned char state = 0;
1256 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
1258 #ifdef CONFIG_QDIO_DEBUG
1262 no_used=atomic_read(&q->number_of_buffers_used);
1265 * we need that one for synchronization with the adapter, as it
1266 * does a kind of PCI avoidance
1271 QDIO_DBF_TEXT4(0,trace,"inqisdnA");
1272 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1275 if (irq->is_qebsm) {
1277 start_buf = q->first_to_check;
1278 qdio_do_eqbs(q, &state, &start_buf, &count);
1280 state = q->slsb.acc.val[q->first_to_check];
1281 if (state == SLSB_P_INPUT_PRIMED) {
1282 /* we got something to do */
1283 QDIO_DBF_TEXT4(0,trace,"inqisntA");
1284 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1288 /* on VM, we don't poll, so the q is always done here */
1291 if (q->hydra_gives_outbound_pcis)
1295 * at this point we know, that inbound first_to_check
1296 * has (probably) not moved (see qdio_inbound_processing)
1298 if (NOW>GET_SAVED_TIMESTAMP(q)+q->timing.threshold) {
1299 #ifdef CONFIG_QDIO_DEBUG
1300 QDIO_DBF_TEXT4(0,trace,"inqisdon");
1301 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1302 sprintf(dbf_text,"pf%02xcn%02x",q->first_to_check,no_used);
1303 QDIO_DBF_TEXT4(0,trace,dbf_text);
1304 #endif /* CONFIG_QDIO_DEBUG */
1307 #ifdef CONFIG_QDIO_DEBUG
1308 QDIO_DBF_TEXT4(0,trace,"inqisntd");
1309 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1310 sprintf(dbf_text,"pf%02xcn%02x",q->first_to_check,no_used);
1311 QDIO_DBF_TEXT4(0,trace,dbf_text);
1312 #endif /* CONFIG_QDIO_DEBUG */
1318 qdio_kick_inbound_handler(struct qdio_q *q)
1320 int count, start, end, real_end, i;
1321 #ifdef CONFIG_QDIO_DEBUG
1325 QDIO_DBF_TEXT4(0,trace,"kickinh");
1326 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1328 start=q->first_element_to_kick;
1329 real_end=q->first_to_check;
1330 end=(real_end+QDIO_MAX_BUFFERS_PER_Q-1)&(QDIO_MAX_BUFFERS_PER_Q-1);
1338 i=(i+1)&(QDIO_MAX_BUFFERS_PER_Q-1);
1341 #ifdef CONFIG_QDIO_DEBUG
1342 sprintf(dbf_text,"s=%2xc=%2x",start,count);
1343 QDIO_DBF_TEXT4(0,trace,dbf_text);
1344 #endif /* CONFIG_QDIO_DEBUG */
1346 if (likely(q->state==QDIO_IRQ_STATE_ACTIVE))
1348 QDIO_STATUS_INBOUND_INT|q->error_status_flags,
1349 q->qdio_error,q->siga_error,q->q_no,start,count,
1352 /* for the next time: */
1353 q->first_element_to_kick=real_end;
1356 q->error_status_flags=0;
1358 qdio_perf_stat_inc(&perf_stats.inbound_cnt);
1362 __tiqdio_inbound_processing(struct qdio_q *q, int spare_ind_was_set)
1364 struct qdio_irq *irq_ptr;
1368 QDIO_DBF_TEXT4(0,trace,"iqinproc");
1369 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1372 * we first want to reserve the q, so that we know, that we don't
1373 * interrupt ourselves and call qdio_unmark_q, as is_in_shutdown might
1376 if (unlikely(qdio_reserve_q(q))) {
1378 qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs_resched);
1380 * as we might just be about to stop polling, we make
1381 * sure that we check again at least once more
1386 qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs);
1387 if (unlikely(atomic_read(&q->is_in_shutdown))) {
1393 * we reset spare_ind_was_set, when the queue does not use the
1396 if (spare_ind_was_set)
1397 spare_ind_was_set = (q->dev_st_chg_ind == &spare_indicator);
1399 if (!(*(q->dev_st_chg_ind)) && !spare_ind_was_set)
1402 * q->dev_st_chg_ind is the indicator, be it shared or not.
1403 * only clear it, if indicator is non-shared
1405 if (!spare_ind_was_set)
1406 tiqdio_clear_summary_bit((__u32*)q->dev_st_chg_ind);
1408 if (q->hydra_gives_outbound_pcis) {
1409 if (!q->siga_sync_done_on_thinints) {
1411 } else if ((!q->siga_sync_done_on_outb_tis)&&
1412 (q->hydra_gives_outbound_pcis)) {
1413 SYNC_MEMORY_ALL_OUTB;
1419 * maybe we have to do work on our outbound queues... at least
1420 * we have to check the outbound-int-capable thinint-capable
1423 if (q->hydra_gives_outbound_pcis) {
1424 irq_ptr = (struct qdio_irq*)q->irq_ptr;
1425 for (i=0;i<irq_ptr->no_output_qs;i++) {
1426 oq = irq_ptr->output_qs[i];
1427 if (!qdio_is_outbound_q_done(oq)) {
1428 qdio_perf_stat_dec(&perf_stats.tl_runs);
1429 __qdio_outbound_processing(oq);
1434 if (!qdio_has_inbound_q_moved(q))
1437 qdio_kick_inbound_handler(q);
1438 if (tiqdio_is_inbound_q_done(q))
1439 if (!qdio_stop_polling(q)) {
1441 * we set the flags to get into the stuff next time,
1442 * see also comment in qdio_stop_polling
1444 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1452 tiqdio_inbound_processing(struct qdio_q *q)
1454 __tiqdio_inbound_processing(q, atomic_read(&spare_indicator_usecount));
1458 __qdio_inbound_processing(struct qdio_q *q)
1462 QDIO_DBF_TEXT4(0,trace,"qinproc");
1463 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
1465 if (unlikely(qdio_reserve_q(q))) {
1467 qdio_perf_stat_inc(&perf_stats.inbound_tl_runs_resched);
1468 /* as we're sissies, we'll check next time */
1469 if (likely(!atomic_read(&q->is_in_shutdown))) {
1471 QDIO_DBF_TEXT4(0,trace,"busy,agn");
1475 qdio_perf_stat_inc(&perf_stats.inbound_tl_runs);
1476 qdio_perf_stat_inc(&perf_stats.tl_runs);
1479 if (qdio_has_inbound_q_moved(q)) {
1480 qdio_kick_inbound_handler(q);
1481 if (!qdio_stop_polling(q)) {
1483 if (q_laps<QDIO_Q_LAPS)
1488 if (!qdio_is_inbound_q_done(q))
1489 /* means poll time is not yet over */
1497 qdio_inbound_processing(struct qdio_q *q)
1499 __qdio_inbound_processing(q);
1502 /************************* MAIN ROUTINES *******************************/
1504 #ifdef QDIO_USE_PROCESSING_STATE
1506 tiqdio_reset_processing_state(struct qdio_q *q, int q_laps)
1514 * under VM, we have not used the PROCESSING state, so no
1515 * need to stop polling
1520 if (unlikely(qdio_reserve_q(q))) {
1522 qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs_resched);
1524 * as we might just be about to stop polling, we make
1525 * sure that we check again at least once more
1529 * sanity -- we'd get here without setting the
1532 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1536 if (qdio_stop_polling(q)) {
1540 if (q_laps<QDIO_Q_LAPS-1) {
1545 * we set the flags to get into the stuff
1546 * next time, see also comment in qdio_stop_polling
1548 tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind);
1554 #endif /* QDIO_USE_PROCESSING_STATE */
1557 tiqdio_inbound_checks(void)
1560 int spare_ind_was_set=0;
1561 #ifdef QDIO_USE_PROCESSING_STATE
1563 #endif /* QDIO_USE_PROCESSING_STATE */
1565 QDIO_DBF_TEXT4(0,trace,"iqdinbck");
1566 QDIO_DBF_TEXT5(0,trace,"iqlocsum");
1568 #ifdef QDIO_USE_PROCESSING_STATE
1570 #endif /* QDIO_USE_PROCESSING_STATE */
1572 /* when the spare indicator is used and set, save that and clear it */
1573 if ((atomic_read(&spare_indicator_usecount)) && spare_indicator) {
1574 spare_ind_was_set = 1;
1575 tiqdio_clear_summary_bit((__u32*)&spare_indicator);
1578 q=(struct qdio_q*)tiq_list;
1582 __tiqdio_inbound_processing(q, spare_ind_was_set);
1583 q=(struct qdio_q*)q->list_next;
1584 } while (q!=(struct qdio_q*)tiq_list);
1586 #ifdef QDIO_USE_PROCESSING_STATE
1587 q=(struct qdio_q*)tiq_list;
1591 ret = tiqdio_reset_processing_state(q, q_laps);
1598 q = (struct qdio_q*)q->list_next;
1604 } while (q!=(struct qdio_q*)tiq_list);
1605 #endif /* QDIO_USE_PROCESSING_STATE */
1609 tiqdio_tl(unsigned long data)
1611 QDIO_DBF_TEXT4(0,trace,"iqdio_tl");
1613 qdio_perf_stat_inc(&perf_stats.tl_runs);
1615 tiqdio_inbound_checks();
1618 /********************* GENERAL HELPER_ROUTINES ***********************/
1621 qdio_release_irq_memory(struct qdio_irq *irq_ptr)
1626 for (i = 0; i < QDIO_MAX_QUEUES_PER_IRQ; i++) {
1627 q = irq_ptr->input_qs[i];
1629 free_page((unsigned long) q->slib);
1630 kmem_cache_free(qdio_q_cache, q);
1632 q = irq_ptr->output_qs[i];
1634 free_page((unsigned long) q->slib);
1635 kmem_cache_free(qdio_q_cache, q);
1638 free_page((unsigned long) irq_ptr->qdr);
1639 free_page((unsigned long) irq_ptr);
1643 qdio_set_impl_params(struct qdio_irq *irq_ptr,
1644 unsigned int qib_param_field_format,
1645 /* pointer to 128 bytes or NULL, if no param field */
1646 unsigned char *qib_param_field,
1647 /* pointer to no_queues*128 words of data or NULL */
1648 unsigned int no_input_qs,
1649 unsigned int no_output_qs,
1650 unsigned long *input_slib_elements,
1651 unsigned long *output_slib_elements)
1658 irq_ptr->qib.pfmt=qib_param_field_format;
1659 if (qib_param_field)
1660 memcpy(irq_ptr->qib.parm,qib_param_field,
1661 QDIO_MAX_BUFFERS_PER_Q);
1663 if (input_slib_elements)
1664 for (i=0;i<no_input_qs;i++) {
1665 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1666 irq_ptr->input_qs[i]->slib->slibe[j].parms=
1667 input_slib_elements[
1668 i*QDIO_MAX_BUFFERS_PER_Q+j];
1670 if (output_slib_elements)
1671 for (i=0;i<no_output_qs;i++) {
1672 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1673 irq_ptr->output_qs[i]->slib->slibe[j].parms=
1674 output_slib_elements[
1675 i*QDIO_MAX_BUFFERS_PER_Q+j];
1680 qdio_alloc_qs(struct qdio_irq *irq_ptr,
1681 int no_input_qs, int no_output_qs)
1686 for (i = 0; i < no_input_qs; i++) {
1687 q = kmem_cache_alloc(qdio_q_cache, GFP_KERNEL);
1690 memset(q, 0, sizeof(*q));
1692 q->slib = (struct slib *) __get_free_page(GFP_KERNEL);
1694 kmem_cache_free(qdio_q_cache, q);
1697 irq_ptr->input_qs[i]=q;
1700 for (i = 0; i < no_output_qs; i++) {
1701 q = kmem_cache_alloc(qdio_q_cache, GFP_KERNEL);
1704 memset(q, 0, sizeof(*q));
1706 q->slib = (struct slib *) __get_free_page(GFP_KERNEL);
1708 kmem_cache_free(qdio_q_cache, q);
1711 irq_ptr->output_qs[i]=q;
1717 qdio_fill_qs(struct qdio_irq *irq_ptr, struct ccw_device *cdev,
1718 int no_input_qs, int no_output_qs,
1719 qdio_handler_t *input_handler,
1720 qdio_handler_t *output_handler,
1721 unsigned long int_parm,int q_format,
1722 unsigned long flags,
1723 void **inbound_sbals_array,
1724 void **outbound_sbals_array)
1728 char dbf_text[20]; /* see qdio_initialize */
1732 sprintf(dbf_text,"qfqs%4x",cdev->private->schid.sch_no);
1733 QDIO_DBF_TEXT0(0,setup,dbf_text);
1734 for (i=0;i<no_input_qs;i++) {
1735 q=irq_ptr->input_qs[i];
1737 memset(q,0,((char*)&q->slib)-((char*)q));
1738 sprintf(dbf_text,"in-q%4x",i);
1739 QDIO_DBF_TEXT0(0,setup,dbf_text);
1740 QDIO_DBF_HEX0(0,setup,&q,sizeof(void*));
1742 memset(q->slib,0,PAGE_SIZE);
1743 q->sl=(struct sl*)(((char*)q->slib)+PAGE_SIZE/2);
1747 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1748 q->sbal[j]=*(inbound_sbals_array++);
1750 q->queue_type=q_format;
1751 q->int_parm=int_parm;
1752 q->schid = irq_ptr->schid;
1753 q->irq_ptr = irq_ptr;
1758 q->first_to_check=0;
1760 q->handler=input_handler;
1761 q->dev_st_chg_ind=irq_ptr->dev_st_chg_ind;
1763 q->tasklet.data=(unsigned long)q;
1764 /* q->is_thinint_q isn't valid at this time, but
1765 * irq_ptr->is_thinint_irq is */
1766 q->tasklet.func=(void(*)(unsigned long))
1767 ((irq_ptr->is_thinint_irq)?&tiqdio_inbound_processing:
1768 &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 q->tasklet.data=(unsigned long)q;
1840 q->tasklet.func=(void(*)(unsigned long))
1841 &qdio_outbound_processing;
1842 q->timer.function=(void(*)(unsigned long))
1843 &qdio_outbound_processing;
1844 q->timer.data = (long)q;
1845 init_timer(&q->timer);
1847 atomic_set(&q->busy_siga_counter,0);
1848 q->timing.busy_start=0;
1851 if (i>0) irq_ptr->output_qs[i-1]->slib->nsliba=
1852 (unsigned long)(q->slib);
1853 q->slib->sla=(unsigned long)(q->sl);
1854 q->slib->slsba=(unsigned long)(&q->slsb.acc.val[0]);
1857 for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++)
1858 q->sl->element[j].sbal=(unsigned long)(q->sbal[j]);
1860 QDIO_DBF_TEXT2(0,setup,"sl-sb-b0");
1862 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1863 ptr=(void*)&q->slsb;
1864 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1865 ptr=(void*)q->sbal[0];
1866 QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*));
1869 if (!irq_ptr->is_qebsm) {
1870 unsigned int count = 1;
1871 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++)
1872 set_slsb(q, &j, SLSB_P_OUTPUT_NOT_INIT, &count);
1878 qdio_fill_thresholds(struct qdio_irq *irq_ptr,
1879 unsigned int no_input_qs,
1880 unsigned int no_output_qs,
1881 unsigned int min_input_threshold,
1882 unsigned int max_input_threshold,
1883 unsigned int min_output_threshold,
1884 unsigned int max_output_threshold)
1889 for (i=0;i<no_input_qs;i++) {
1890 q=irq_ptr->input_qs[i];
1891 q->timing.threshold=max_input_threshold;
1892 /* for (j=0;j<QDIO_STATS_CLASSES;j++) {
1893 q->threshold_classes[j].threshold=
1894 min_input_threshold+
1895 (max_input_threshold-min_input_threshold)/
1898 qdio_use_thresholds(q,QDIO_STATS_CLASSES/2);*/
1900 for (i=0;i<no_output_qs;i++) {
1901 q=irq_ptr->output_qs[i];
1902 q->timing.threshold=max_output_threshold;
1903 /* for (j=0;j<QDIO_STATS_CLASSES;j++) {
1904 q->threshold_classes[j].threshold=
1905 min_output_threshold+
1906 (max_output_threshold-min_output_threshold)/
1909 qdio_use_thresholds(q,QDIO_STATS_CLASSES/2);*/
1914 tiqdio_thinint_handler(void)
1916 QDIO_DBF_TEXT4(0,trace,"thin_int");
1918 qdio_perf_stat_inc(&perf_stats.thinints);
1920 /* SVS only when needed:
1921 * issue SVS to benefit from iqdio interrupt avoidance
1922 * (SVS clears AISOI)*/
1924 tiqdio_clear_global_summary();
1926 tiqdio_inbound_checks();
1931 qdio_set_state(struct qdio_irq *irq_ptr, enum qdio_irq_states state)
1934 #ifdef CONFIG_QDIO_DEBUG
1937 QDIO_DBF_TEXT5(0,trace,"newstate");
1938 sprintf(dbf_text,"%4x%4x",irq_ptr->schid.sch_no,state);
1939 QDIO_DBF_TEXT5(0,trace,dbf_text);
1940 #endif /* CONFIG_QDIO_DEBUG */
1942 irq_ptr->state=state;
1943 for (i=0;i<irq_ptr->no_input_qs;i++)
1944 irq_ptr->input_qs[i]->state=state;
1945 for (i=0;i<irq_ptr->no_output_qs;i++)
1946 irq_ptr->output_qs[i]->state=state;
1951 qdio_irq_check_sense(struct subchannel_id schid, struct irb *irb)
1955 if (irb->esw.esw0.erw.cons) {
1956 sprintf(dbf_text,"sens%4x",schid.sch_no);
1957 QDIO_DBF_TEXT2(1,trace,dbf_text);
1958 QDIO_DBF_HEX0(0,sense,irb,QDIO_DBF_SENSE_LEN);
1960 QDIO_PRINT_WARN("sense data available on qdio channel.\n");
1961 QDIO_HEXDUMP16(WARN,"irb: ",irb);
1962 QDIO_HEXDUMP16(WARN,"sense data: ",irb->ecw);
1968 qdio_handle_pci(struct qdio_irq *irq_ptr)
1973 qdio_perf_stat_inc(&perf_stats.pcis);
1974 for (i=0;i<irq_ptr->no_input_qs;i++) {
1975 q=irq_ptr->input_qs[i];
1976 if (q->is_input_q&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT)
1979 qdio_perf_stat_dec(&perf_stats.tl_runs);
1980 __qdio_inbound_processing(q);
1983 if (!irq_ptr->hydra_gives_outbound_pcis)
1985 for (i=0;i<irq_ptr->no_output_qs;i++) {
1986 q=irq_ptr->output_qs[i];
1987 if (qdio_is_outbound_q_done(q))
1989 qdio_perf_stat_dec(&perf_stats.tl_runs);
1990 if (!irq_ptr->sync_done_on_outb_pcis)
1992 __qdio_outbound_processing(q);
1996 static void qdio_establish_handle_irq(struct ccw_device*, int, int);
1999 qdio_handle_activate_check(struct ccw_device *cdev, unsigned long intparm,
2000 int cstat, int dstat)
2002 struct qdio_irq *irq_ptr;
2006 irq_ptr = cdev->private->qdio_data;
2008 QDIO_DBF_TEXT2(1, trace, "ick2");
2009 sprintf(dbf_text,"%s", cdev->dev.bus_id);
2010 QDIO_DBF_TEXT2(1,trace,dbf_text);
2011 QDIO_DBF_HEX2(0,trace,&intparm,sizeof(int));
2012 QDIO_DBF_HEX2(0,trace,&dstat,sizeof(int));
2013 QDIO_DBF_HEX2(0,trace,&cstat,sizeof(int));
2014 QDIO_PRINT_ERR("received check condition on activate " \
2015 "queues on device %s (cs=x%x, ds=x%x).\n",
2016 cdev->dev.bus_id, cstat, dstat);
2017 if (irq_ptr->no_input_qs) {
2018 q=irq_ptr->input_qs[0];
2019 } else if (irq_ptr->no_output_qs) {
2020 q=irq_ptr->output_qs[0];
2022 QDIO_PRINT_ERR("oops... no queue registered for device %s!?\n",
2024 goto omit_handler_call;
2026 q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION|
2027 QDIO_STATUS_LOOK_FOR_ERROR,
2028 0,0,0,-1,-1,q->int_parm);
2030 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_STOPPED);
2035 qdio_call_shutdown(struct work_struct *work)
2037 struct ccw_device_private *priv;
2038 struct ccw_device *cdev;
2040 priv = container_of(work, struct ccw_device_private, kick_work);
2042 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
2043 put_device(&cdev->dev);
2047 qdio_timeout_handler(struct ccw_device *cdev)
2049 struct qdio_irq *irq_ptr;
2052 QDIO_DBF_TEXT2(0, trace, "qtoh");
2053 sprintf(dbf_text, "%s", cdev->dev.bus_id);
2054 QDIO_DBF_TEXT2(0, trace, dbf_text);
2056 irq_ptr = cdev->private->qdio_data;
2057 sprintf(dbf_text, "state:%d", irq_ptr->state);
2058 QDIO_DBF_TEXT2(0, trace, dbf_text);
2060 switch (irq_ptr->state) {
2061 case QDIO_IRQ_STATE_INACTIVE:
2062 QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: timed out\n",
2063 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2064 QDIO_DBF_TEXT2(1,setup,"eq:timeo");
2065 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2067 case QDIO_IRQ_STATE_CLEANUP:
2068 QDIO_PRINT_INFO("Did not get interrupt on cleanup, "
2070 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2071 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2073 case QDIO_IRQ_STATE_ESTABLISHED:
2074 case QDIO_IRQ_STATE_ACTIVE:
2075 /* I/O has been terminated by common I/O layer. */
2076 QDIO_PRINT_INFO("Queues on irq 0.%x.%04x killed by cio.\n",
2077 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2078 QDIO_DBF_TEXT2(1, trace, "cio:term");
2079 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
2080 if (get_device(&cdev->dev)) {
2081 /* Can't call shutdown from interrupt context. */
2082 PREPARE_WORK(&cdev->private->kick_work,
2083 qdio_call_shutdown);
2084 queue_work(ccw_device_work, &cdev->private->kick_work);
2090 ccw_device_set_timeout(cdev, 0);
2091 wake_up(&cdev->private->wait_q);
2095 qdio_handler(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
2097 struct qdio_irq *irq_ptr;
2101 #ifdef CONFIG_QDIO_DEBUG
2102 QDIO_DBF_TEXT4(0, trace, "qint");
2103 sprintf(dbf_text, "%s", cdev->dev.bus_id);
2104 QDIO_DBF_TEXT4(0, trace, dbf_text);
2105 #endif /* CONFIG_QDIO_DEBUG */
2108 QDIO_PRINT_ERR("got unsolicited interrupt in qdio " \
2109 "handler, device %s\n", cdev->dev.bus_id);
2113 irq_ptr = cdev->private->qdio_data;
2115 QDIO_DBF_TEXT2(1, trace, "uint");
2116 sprintf(dbf_text,"%s", cdev->dev.bus_id);
2117 QDIO_DBF_TEXT2(1,trace,dbf_text);
2118 QDIO_PRINT_ERR("received interrupt on unused device %s!\n",
2124 /* Currently running i/o is in error. */
2125 switch (PTR_ERR(irb)) {
2127 QDIO_PRINT_ERR("i/o error on device %s\n",
2131 qdio_timeout_handler(cdev);
2134 QDIO_PRINT_ERR("unknown error state %ld on device %s\n",
2135 PTR_ERR(irb), cdev->dev.bus_id);
2140 qdio_irq_check_sense(irq_ptr->schid, irb);
2142 #ifdef CONFIG_QDIO_DEBUG
2143 sprintf(dbf_text, "state:%d", irq_ptr->state);
2144 QDIO_DBF_TEXT4(0, trace, dbf_text);
2145 #endif /* CONFIG_QDIO_DEBUG */
2147 cstat = irb->scsw.cstat;
2148 dstat = irb->scsw.dstat;
2150 switch (irq_ptr->state) {
2151 case QDIO_IRQ_STATE_INACTIVE:
2152 qdio_establish_handle_irq(cdev, cstat, dstat);
2155 case QDIO_IRQ_STATE_CLEANUP:
2156 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2159 case QDIO_IRQ_STATE_ESTABLISHED:
2160 case QDIO_IRQ_STATE_ACTIVE:
2161 if (cstat & SCHN_STAT_PCI) {
2162 qdio_handle_pci(irq_ptr);
2166 if ((cstat&~SCHN_STAT_PCI)||dstat) {
2167 qdio_handle_activate_check(cdev, intparm, cstat, dstat);
2171 QDIO_PRINT_ERR("got interrupt for queues in state %d on " \
2173 irq_ptr->state, cdev->dev.bus_id);
2175 wake_up(&cdev->private->wait_q);
2180 qdio_synchronize(struct ccw_device *cdev, unsigned int flags,
2181 unsigned int queue_number)
2185 struct qdio_irq *irq_ptr;
2187 #ifdef CONFIG_QDIO_DEBUG
2188 char dbf_text[15]="SyncXXXX";
2191 irq_ptr = cdev->private->qdio_data;
2195 #ifdef CONFIG_QDIO_DEBUG
2196 *((int*)(&dbf_text[4])) = irq_ptr->schid.sch_no;
2197 QDIO_DBF_HEX4(0,trace,dbf_text,QDIO_DBF_TRACE_LEN);
2198 *((int*)(&dbf_text[0]))=flags;
2199 *((int*)(&dbf_text[4]))=queue_number;
2200 QDIO_DBF_HEX4(0,trace,dbf_text,QDIO_DBF_TRACE_LEN);
2201 #endif /* CONFIG_QDIO_DEBUG */
2203 if (flags&QDIO_FLAG_SYNC_INPUT) {
2204 q=irq_ptr->input_qs[queue_number];
2207 if (!(irq_ptr->is_qebsm))
2208 cc = do_siga_sync(q->schid, 0, q->mask);
2209 } else if (flags&QDIO_FLAG_SYNC_OUTPUT) {
2210 q=irq_ptr->output_qs[queue_number];
2213 if (!(irq_ptr->is_qebsm))
2214 cc = do_siga_sync(q->schid, q->mask, 0);
2220 QDIO_DBF_HEX3(0,trace,&ptr,sizeof(int));
2226 qdio_check_subchannel_qebsm(struct qdio_irq *irq_ptr, unsigned char qdioac,
2227 unsigned long token)
2231 unsigned int count, start_buf;
2234 /*check if QEBSM is disabled */
2235 if (!(irq_ptr->is_qebsm) || !(qdioac & 0x01)) {
2236 irq_ptr->is_qebsm = 0;
2237 irq_ptr->sch_token = 0;
2238 irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM;
2239 QDIO_DBF_TEXT0(0,setup,"noV=V");
2242 irq_ptr->sch_token = token;
2244 for (i = 0; i < irq_ptr->no_input_qs;i++) {
2245 q = irq_ptr->input_qs[i];
2246 count = QDIO_MAX_BUFFERS_PER_Q;
2248 set_slsb(q, &start_buf, SLSB_P_INPUT_NOT_INIT, &count);
2250 sprintf(dbf_text,"V=V:%2x",irq_ptr->is_qebsm);
2251 QDIO_DBF_TEXT0(0,setup,dbf_text);
2252 sprintf(dbf_text,"%8lx",irq_ptr->sch_token);
2253 QDIO_DBF_TEXT0(0,setup,dbf_text);
2255 for (i = 0; i < irq_ptr->no_output_qs; i++) {
2256 q = irq_ptr->output_qs[i];
2257 count = QDIO_MAX_BUFFERS_PER_Q;
2259 set_slsb(q, &start_buf, SLSB_P_OUTPUT_NOT_INIT, &count);
2264 qdio_get_ssqd_information(struct qdio_irq *irq_ptr)
2267 unsigned char qdioac;
2269 struct chsc_header request;
2277 struct chsc_header response;
2296 QDIO_DBF_TEXT0(0,setup,"getssqd");
2298 ssqd_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC);
2300 QDIO_PRINT_WARN("Could not get memory for chsc. Using all " \
2301 "SIGAs for sch x%x.\n", irq_ptr->schid.sch_no);
2302 irq_ptr->qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY |
2303 CHSC_FLAG_SIGA_OUTPUT_NECESSARY |
2304 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */
2305 irq_ptr->is_qebsm = 0;
2306 irq_ptr->sch_token = 0;
2307 irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM;
2311 ssqd_area->request = (struct chsc_header) {
2315 ssqd_area->first_sch = irq_ptr->schid.sch_no;
2316 ssqd_area->last_sch = irq_ptr->schid.sch_no;
2317 ssqd_area->ssid = irq_ptr->schid.ssid;
2318 result = chsc(ssqd_area);
2321 QDIO_PRINT_WARN("CHSC returned cc %i. Using all " \
2322 "SIGAs for sch 0.%x.%x.\n", result,
2323 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2324 qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY |
2325 CHSC_FLAG_SIGA_OUTPUT_NECESSARY |
2326 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */
2327 irq_ptr->is_qebsm = 0;
2331 if (ssqd_area->response.code != QDIO_CHSC_RESPONSE_CODE_OK) {
2332 QDIO_PRINT_WARN("response upon checking SIGA needs " \
2333 "is 0x%x. Using all SIGAs for sch 0.%x.%x.\n",
2334 ssqd_area->response.code,
2335 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2336 qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY |
2337 CHSC_FLAG_SIGA_OUTPUT_NECESSARY |
2338 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */
2339 irq_ptr->is_qebsm = 0;
2342 if (!(ssqd_area->flags & CHSC_FLAG_QDIO_CAPABILITY) ||
2343 !(ssqd_area->flags & CHSC_FLAG_VALIDITY) ||
2344 (ssqd_area->sch != irq_ptr->schid.sch_no)) {
2345 QDIO_PRINT_WARN("huh? problems checking out sch 0.%x.%x... " \
2346 "using all SIGAs.\n",
2347 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2348 qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY |
2349 CHSC_FLAG_SIGA_OUTPUT_NECESSARY |
2350 CHSC_FLAG_SIGA_SYNC_NECESSARY; /* worst case */
2351 irq_ptr->is_qebsm = 0;
2354 qdioac = ssqd_area->qdioac1;
2356 qdio_check_subchannel_qebsm(irq_ptr, qdioac,
2357 ssqd_area->sch_token);
2358 mempool_free(ssqd_area, qdio_mempool_scssc);
2359 irq_ptr->qdioac = qdioac;
2363 tiqdio_check_chsc_availability(void)
2367 if (!css_characteristics_avail)
2370 /* Check for bit 41. */
2371 if (!css_general_characteristics.aif) {
2372 QDIO_PRINT_WARN("Adapter interruption facility not " \
2377 /* Check for bits 107 and 108. */
2378 if (!css_chsc_characteristics.scssc ||
2379 !css_chsc_characteristics.scsscf) {
2380 QDIO_PRINT_WARN("Set Chan Subsys. Char. & Fast-CHSCs " \
2381 "not available.\n");
2385 /* Check for OSA/FCP thin interrupts (bit 67). */
2386 hydra_thinints = css_general_characteristics.aif_osa;
2387 sprintf(dbf_text,"hydrati%1x", hydra_thinints);
2388 QDIO_DBF_TEXT0(0,setup,dbf_text);
2391 /* Check for QEBSM support in general (bit 58). */
2392 is_passthrough = css_general_characteristics.qebsm;
2394 sprintf(dbf_text,"cssQBS:%1x", is_passthrough);
2395 QDIO_DBF_TEXT0(0,setup,dbf_text);
2397 /* Check for aif time delay disablement fac (bit 56). If installed,
2398 * omit svs even under lpar (good point by rick again) */
2399 omit_svs = css_general_characteristics.aif_tdd;
2400 sprintf(dbf_text,"omitsvs%1x", omit_svs);
2401 QDIO_DBF_TEXT0(0,setup,dbf_text);
2407 tiqdio_set_subchannel_ind(struct qdio_irq *irq_ptr, int reset_to_zero)
2409 unsigned long real_addr_local_summary_bit;
2410 unsigned long real_addr_dev_st_chg_ind;
2414 unsigned int resp_code;
2418 struct chsc_header request;
2423 u64 summary_indicator_addr;
2424 u64 subchannel_indicator_addr;
2429 u32 word_with_d_bit;
2430 /* set to 0x10000000 to enable
2431 * time delay disablement facility */
2433 struct subchannel_id schid;
2434 u32 reserved6[1004];
2435 struct chsc_header response;
2439 if (!irq_ptr->is_thinint_irq)
2442 if (reset_to_zero) {
2443 real_addr_local_summary_bit=0;
2444 real_addr_dev_st_chg_ind=0;
2446 real_addr_local_summary_bit=
2447 virt_to_phys((volatile void *)indicators);
2448 real_addr_dev_st_chg_ind=
2449 virt_to_phys((volatile void *)irq_ptr->dev_st_chg_ind);
2452 scssc_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC);
2454 QDIO_PRINT_WARN("No memory for setting indicators on " \
2455 "subchannel 0.%x.%x.\n",
2456 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2459 scssc_area->request = (struct chsc_header) {
2463 scssc_area->operation_code = 0;
2465 scssc_area->summary_indicator_addr = real_addr_local_summary_bit;
2466 scssc_area->subchannel_indicator_addr = real_addr_dev_st_chg_ind;
2467 scssc_area->ks = QDIO_STORAGE_KEY;
2468 scssc_area->kc = QDIO_STORAGE_KEY;
2469 scssc_area->isc = TIQDIO_THININT_ISC;
2470 scssc_area->schid = irq_ptr->schid;
2471 /* enables the time delay disablement facility. Don't care
2472 * whether it is really there (i.e. we haven't checked for
2474 if (css_general_characteristics.aif_tdd)
2475 scssc_area->word_with_d_bit = 0x10000000;
2477 QDIO_PRINT_WARN("Time delay disablement facility " \
2480 result = chsc(scssc_area);
2482 QDIO_PRINT_WARN("could not set indicators on irq 0.%x.%x, " \
2484 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,result);
2489 resp_code = scssc_area->response.code;
2490 if (resp_code!=QDIO_CHSC_RESPONSE_CODE_OK) {
2491 QDIO_PRINT_WARN("response upon setting indicators " \
2492 "is 0x%x.\n",resp_code);
2493 sprintf(dbf_text,"sidR%4x",resp_code);
2494 QDIO_DBF_TEXT1(0,trace,dbf_text);
2495 QDIO_DBF_TEXT1(0,setup,dbf_text);
2496 ptr=&scssc_area->response;
2497 QDIO_DBF_HEX2(1,setup,&ptr,QDIO_DBF_SETUP_LEN);
2502 QDIO_DBF_TEXT2(0,setup,"setscind");
2503 QDIO_DBF_HEX2(0,setup,&real_addr_local_summary_bit,
2504 sizeof(unsigned long));
2505 QDIO_DBF_HEX2(0,setup,&real_addr_dev_st_chg_ind,sizeof(unsigned long));
2508 mempool_free(scssc_area, qdio_mempool_scssc);
2514 tiqdio_set_delay_target(struct qdio_irq *irq_ptr, unsigned long delay_target)
2516 unsigned int resp_code;
2522 struct chsc_header request;
2529 u32 reserved5[1009];
2530 struct chsc_header response;
2534 if (!irq_ptr->is_thinint_irq)
2537 scsscf_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC);
2539 QDIO_PRINT_WARN("No memory for setting delay target on " \
2540 "subchannel 0.%x.%x.\n",
2541 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
2544 scsscf_area->request = (struct chsc_header) {
2549 scsscf_area->delay_target = delay_target<<16;
2551 result=chsc(scsscf_area);
2553 QDIO_PRINT_WARN("could not set delay target on irq 0.%x.%x, " \
2554 "cc=%i. Continuing.\n",
2555 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
2561 resp_code = scsscf_area->response.code;
2562 if (resp_code!=QDIO_CHSC_RESPONSE_CODE_OK) {
2563 QDIO_PRINT_WARN("response upon setting delay target " \
2564 "is 0x%x. Continuing.\n",resp_code);
2565 sprintf(dbf_text,"sdtR%4x",resp_code);
2566 QDIO_DBF_TEXT1(0,trace,dbf_text);
2567 QDIO_DBF_TEXT1(0,setup,dbf_text);
2568 ptr=&scsscf_area->response;
2569 QDIO_DBF_HEX2(1,trace,&ptr,QDIO_DBF_TRACE_LEN);
2571 QDIO_DBF_TEXT2(0,trace,"delytrgt");
2572 QDIO_DBF_HEX2(0,trace,&delay_target,sizeof(unsigned long));
2573 result = 0; /* not critical */
2575 mempool_free(scsscf_area, qdio_mempool_scssc);
2580 qdio_cleanup(struct ccw_device *cdev, int how)
2582 struct qdio_irq *irq_ptr;
2586 irq_ptr = cdev->private->qdio_data;
2590 sprintf(dbf_text,"qcln%4x",irq_ptr->schid.sch_no);
2591 QDIO_DBF_TEXT1(0,trace,dbf_text);
2592 QDIO_DBF_TEXT0(0,setup,dbf_text);
2594 rc = qdio_shutdown(cdev, how);
2595 if ((rc == 0) || (rc == -EINPROGRESS))
2596 rc = qdio_free(cdev);
2601 qdio_shutdown(struct ccw_device *cdev, int how)
2603 struct qdio_irq *irq_ptr;
2607 unsigned long flags;
2611 irq_ptr = cdev->private->qdio_data;
2615 down(&irq_ptr->setting_up_sema);
2617 sprintf(dbf_text,"qsqs%4x",irq_ptr->schid.sch_no);
2618 QDIO_DBF_TEXT1(0,trace,dbf_text);
2619 QDIO_DBF_TEXT0(0,setup,dbf_text);
2621 /* mark all qs as uninteresting */
2622 for (i=0;i<irq_ptr->no_input_qs;i++)
2623 atomic_set(&irq_ptr->input_qs[i]->is_in_shutdown,1);
2625 for (i=0;i<irq_ptr->no_output_qs;i++)
2626 atomic_set(&irq_ptr->output_qs[i]->is_in_shutdown,1);
2628 tasklet_kill(&tiqdio_tasklet);
2630 for (i=0;i<irq_ptr->no_input_qs;i++) {
2631 qdio_unmark_q(irq_ptr->input_qs[i]);
2632 tasklet_kill(&irq_ptr->input_qs[i]->tasklet);
2633 wait_event_interruptible_timeout(cdev->private->wait_q,
2634 !atomic_read(&irq_ptr->
2637 QDIO_NO_USE_COUNT_TIMEOUT);
2638 if (atomic_read(&irq_ptr->input_qs[i]->use_count))
2639 result=-EINPROGRESS;
2642 for (i=0;i<irq_ptr->no_output_qs;i++) {
2643 tasklet_kill(&irq_ptr->output_qs[i]->tasklet);
2644 del_timer(&irq_ptr->output_qs[i]->timer);
2645 wait_event_interruptible_timeout(cdev->private->wait_q,
2646 !atomic_read(&irq_ptr->
2649 QDIO_NO_USE_COUNT_TIMEOUT);
2650 if (atomic_read(&irq_ptr->output_qs[i]->use_count))
2651 result=-EINPROGRESS;
2654 /* cleanup subchannel */
2655 spin_lock_irqsave(get_ccwdev_lock(cdev),flags);
2656 if (how&QDIO_FLAG_CLEANUP_USING_CLEAR) {
2657 rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
2658 timeout=QDIO_CLEANUP_CLEAR_TIMEOUT;
2659 } else if (how&QDIO_FLAG_CLEANUP_USING_HALT) {
2660 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
2661 timeout=QDIO_CLEANUP_HALT_TIMEOUT;
2662 } else { /* default behaviour */
2663 rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
2664 timeout=QDIO_CLEANUP_HALT_TIMEOUT;
2666 if (rc == -ENODEV) {
2667 /* No need to wait for device no longer present. */
2668 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2669 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2670 } else if (((void *)cdev->handler != (void *)qdio_handler) && rc == 0) {
2672 * Whoever put another handler there, has to cope with the
2673 * interrupt theirself. Might happen if qdio_shutdown was
2674 * called on already shutdown queues, but this shouldn't have
2677 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2678 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2679 } else if (rc == 0) {
2680 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
2681 ccw_device_set_timeout(cdev, timeout);
2682 spin_unlock_irqrestore(get_ccwdev_lock(cdev),flags);
2684 wait_event(cdev->private->wait_q,
2685 irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
2686 irq_ptr->state == QDIO_IRQ_STATE_ERR);
2688 QDIO_PRINT_INFO("ccw_device_{halt,clear} returned %d for "
2689 "device %s\n", result, cdev->dev.bus_id);
2690 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2694 if (irq_ptr->is_thinint_irq) {
2695 qdio_put_indicator((__u32*)irq_ptr->dev_st_chg_ind);
2696 tiqdio_set_subchannel_ind(irq_ptr,1);
2697 /* reset adapter interrupt indicators */
2700 /* exchange int handlers, if necessary */
2701 if ((void*)cdev->handler == (void*)qdio_handler)
2702 cdev->handler=irq_ptr->original_int_handler;
2704 /* Ignore errors. */
2705 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
2706 ccw_device_set_timeout(cdev, 0);
2708 up(&irq_ptr->setting_up_sema);
2713 qdio_free(struct ccw_device *cdev)
2715 struct qdio_irq *irq_ptr;
2718 irq_ptr = cdev->private->qdio_data;
2722 down(&irq_ptr->setting_up_sema);
2724 sprintf(dbf_text,"qfqs%4x",irq_ptr->schid.sch_no);
2725 QDIO_DBF_TEXT1(0,trace,dbf_text);
2726 QDIO_DBF_TEXT0(0,setup,dbf_text);
2728 cdev->private->qdio_data = NULL;
2730 up(&irq_ptr->setting_up_sema);
2732 qdio_release_irq_memory(irq_ptr);
2733 module_put(THIS_MODULE);
2738 qdio_allocate_do_dbf(struct qdio_initialize *init_data)
2740 char dbf_text[20]; /* if a printf printed out more than 8 chars */
2742 sprintf(dbf_text,"qfmt:%x",init_data->q_format);
2743 QDIO_DBF_TEXT0(0,setup,dbf_text);
2744 QDIO_DBF_HEX0(0,setup,init_data->adapter_name,8);
2745 sprintf(dbf_text,"qpff%4x",init_data->qib_param_field_format);
2746 QDIO_DBF_TEXT0(0,setup,dbf_text);
2747 QDIO_DBF_HEX0(0,setup,&init_data->qib_param_field,sizeof(char*));
2748 QDIO_DBF_HEX0(0,setup,&init_data->input_slib_elements,sizeof(long*));
2749 QDIO_DBF_HEX0(0,setup,&init_data->output_slib_elements,sizeof(long*));
2750 sprintf(dbf_text,"miit%4x",init_data->min_input_threshold);
2751 QDIO_DBF_TEXT0(0,setup,dbf_text);
2752 sprintf(dbf_text,"mait%4x",init_data->max_input_threshold);
2753 QDIO_DBF_TEXT0(0,setup,dbf_text);
2754 sprintf(dbf_text,"miot%4x",init_data->min_output_threshold);
2755 QDIO_DBF_TEXT0(0,setup,dbf_text);
2756 sprintf(dbf_text,"maot%4x",init_data->max_output_threshold);
2757 QDIO_DBF_TEXT0(0,setup,dbf_text);
2758 sprintf(dbf_text,"niq:%4x",init_data->no_input_qs);
2759 QDIO_DBF_TEXT0(0,setup,dbf_text);
2760 sprintf(dbf_text,"noq:%4x",init_data->no_output_qs);
2761 QDIO_DBF_TEXT0(0,setup,dbf_text);
2762 QDIO_DBF_HEX0(0,setup,&init_data->input_handler,sizeof(void*));
2763 QDIO_DBF_HEX0(0,setup,&init_data->output_handler,sizeof(void*));
2764 QDIO_DBF_HEX0(0,setup,&init_data->int_parm,sizeof(long));
2765 QDIO_DBF_HEX0(0,setup,&init_data->flags,sizeof(long));
2766 QDIO_DBF_HEX0(0,setup,&init_data->input_sbal_addr_array,sizeof(void*));
2767 QDIO_DBF_HEX0(0,setup,&init_data->output_sbal_addr_array,sizeof(void*));
2771 qdio_allocate_fill_input_desc(struct qdio_irq *irq_ptr, int i, int iqfmt)
2773 irq_ptr->input_qs[i]->is_iqdio_q = iqfmt;
2774 irq_ptr->input_qs[i]->is_thinint_q = irq_ptr->is_thinint_irq;
2776 irq_ptr->qdr->qdf0[i].sliba=(unsigned long)(irq_ptr->input_qs[i]->slib);
2778 irq_ptr->qdr->qdf0[i].sla=(unsigned long)(irq_ptr->input_qs[i]->sl);
2780 irq_ptr->qdr->qdf0[i].slsba=
2781 (unsigned long)(&irq_ptr->input_qs[i]->slsb.acc.val[0]);
2783 irq_ptr->qdr->qdf0[i].akey=QDIO_STORAGE_KEY;
2784 irq_ptr->qdr->qdf0[i].bkey=QDIO_STORAGE_KEY;
2785 irq_ptr->qdr->qdf0[i].ckey=QDIO_STORAGE_KEY;
2786 irq_ptr->qdr->qdf0[i].dkey=QDIO_STORAGE_KEY;
2790 qdio_allocate_fill_output_desc(struct qdio_irq *irq_ptr, int i,
2793 irq_ptr->output_qs[i]->is_iqdio_q = iqfmt;
2794 irq_ptr->output_qs[i]->is_thinint_q = irq_ptr->is_thinint_irq;
2796 irq_ptr->qdr->qdf0[i+j].sliba=(unsigned long)(irq_ptr->output_qs[i]->slib);
2798 irq_ptr->qdr->qdf0[i+j].sla=(unsigned long)(irq_ptr->output_qs[i]->sl);
2800 irq_ptr->qdr->qdf0[i+j].slsba=
2801 (unsigned long)(&irq_ptr->output_qs[i]->slsb.acc.val[0]);
2803 irq_ptr->qdr->qdf0[i+j].akey=QDIO_STORAGE_KEY;
2804 irq_ptr->qdr->qdf0[i+j].bkey=QDIO_STORAGE_KEY;
2805 irq_ptr->qdr->qdf0[i+j].ckey=QDIO_STORAGE_KEY;
2806 irq_ptr->qdr->qdf0[i+j].dkey=QDIO_STORAGE_KEY;
2811 qdio_initialize_set_siga_flags_input(struct qdio_irq *irq_ptr)
2815 for (i=0;i<irq_ptr->no_input_qs;i++) {
2816 irq_ptr->input_qs[i]->siga_sync=
2817 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY;
2818 irq_ptr->input_qs[i]->siga_in=
2819 irq_ptr->qdioac&CHSC_FLAG_SIGA_INPUT_NECESSARY;
2820 irq_ptr->input_qs[i]->siga_out=
2821 irq_ptr->qdioac&CHSC_FLAG_SIGA_OUTPUT_NECESSARY;
2822 irq_ptr->input_qs[i]->siga_sync_done_on_thinints=
2823 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS;
2824 irq_ptr->input_qs[i]->hydra_gives_outbound_pcis=
2825 irq_ptr->hydra_gives_outbound_pcis;
2826 irq_ptr->input_qs[i]->siga_sync_done_on_outb_tis=
2828 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2829 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS))==
2830 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2831 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS));
2837 qdio_initialize_set_siga_flags_output(struct qdio_irq *irq_ptr)
2841 for (i=0;i<irq_ptr->no_output_qs;i++) {
2842 irq_ptr->output_qs[i]->siga_sync=
2843 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY;
2844 irq_ptr->output_qs[i]->siga_in=
2845 irq_ptr->qdioac&CHSC_FLAG_SIGA_INPUT_NECESSARY;
2846 irq_ptr->output_qs[i]->siga_out=
2847 irq_ptr->qdioac&CHSC_FLAG_SIGA_OUTPUT_NECESSARY;
2848 irq_ptr->output_qs[i]->siga_sync_done_on_thinints=
2849 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS;
2850 irq_ptr->output_qs[i]->hydra_gives_outbound_pcis=
2851 irq_ptr->hydra_gives_outbound_pcis;
2852 irq_ptr->output_qs[i]->siga_sync_done_on_outb_tis=
2854 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2855 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS))==
2856 (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS|
2857 CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS));
2863 qdio_establish_irq_check_for_errors(struct ccw_device *cdev, int cstat,
2867 struct qdio_irq *irq_ptr;
2869 irq_ptr = cdev->private->qdio_data;
2871 if (cstat || (dstat & ~(DEV_STAT_CHN_END|DEV_STAT_DEV_END))) {
2872 sprintf(dbf_text,"ick1%4x",irq_ptr->schid.sch_no);
2873 QDIO_DBF_TEXT2(1,trace,dbf_text);
2874 QDIO_DBF_HEX2(0,trace,&dstat,sizeof(int));
2875 QDIO_DBF_HEX2(0,trace,&cstat,sizeof(int));
2876 QDIO_PRINT_ERR("received check condition on establish " \
2877 "queues on irq 0.%x.%x (cs=x%x, ds=x%x).\n",
2878 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
2880 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ERR);
2883 if (!(dstat & DEV_STAT_DEV_END)) {
2884 QDIO_DBF_TEXT2(1,setup,"eq:no de");
2885 QDIO_DBF_HEX2(0,setup,&dstat, sizeof(dstat));
2886 QDIO_DBF_HEX2(0,setup,&cstat, sizeof(cstat));
2887 QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: didn't get "
2888 "device end: dstat=%02x, cstat=%02x\n",
2889 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
2891 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2895 if (dstat & ~(DEV_STAT_CHN_END|DEV_STAT_DEV_END)) {
2896 QDIO_DBF_TEXT2(1,setup,"eq:badio");
2897 QDIO_DBF_HEX2(0,setup,&dstat, sizeof(dstat));
2898 QDIO_DBF_HEX2(0,setup,&cstat, sizeof(cstat));
2899 QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: got "
2900 "the following devstat: dstat=%02x, "
2901 "cstat=%02x\n", irq_ptr->schid.ssid,
2902 irq_ptr->schid.sch_no, dstat, cstat);
2903 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
2910 qdio_establish_handle_irq(struct ccw_device *cdev, int cstat, int dstat)
2912 struct qdio_irq *irq_ptr;
2915 irq_ptr = cdev->private->qdio_data;
2917 sprintf(dbf_text,"qehi%4x",cdev->private->schid.sch_no);
2918 QDIO_DBF_TEXT0(0,setup,dbf_text);
2919 QDIO_DBF_TEXT0(0,trace,dbf_text);
2921 if (qdio_establish_irq_check_for_errors(cdev, cstat, dstat)) {
2922 ccw_device_set_timeout(cdev, 0);
2926 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ESTABLISHED);
2927 ccw_device_set_timeout(cdev, 0);
2931 qdio_initialize(struct qdio_initialize *init_data)
2936 sprintf(dbf_text,"qini%4x",init_data->cdev->private->schid.sch_no);
2937 QDIO_DBF_TEXT0(0,setup,dbf_text);
2938 QDIO_DBF_TEXT0(0,trace,dbf_text);
2940 rc = qdio_allocate(init_data);
2942 rc = qdio_establish(init_data);
2944 qdio_free(init_data->cdev);
2952 qdio_allocate(struct qdio_initialize *init_data)
2954 struct qdio_irq *irq_ptr;
2957 sprintf(dbf_text,"qalc%4x",init_data->cdev->private->schid.sch_no);
2958 QDIO_DBF_TEXT0(0,setup,dbf_text);
2959 QDIO_DBF_TEXT0(0,trace,dbf_text);
2960 if ( (init_data->no_input_qs>QDIO_MAX_QUEUES_PER_IRQ) ||
2961 (init_data->no_output_qs>QDIO_MAX_QUEUES_PER_IRQ) ||
2962 ((init_data->no_input_qs) && (!init_data->input_handler)) ||
2963 ((init_data->no_output_qs) && (!init_data->output_handler)) )
2966 if (!init_data->input_sbal_addr_array)
2969 if (!init_data->output_sbal_addr_array)
2972 qdio_allocate_do_dbf(init_data);
2975 irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
2977 QDIO_DBF_TEXT0(0,setup,"irq_ptr:");
2978 QDIO_DBF_HEX0(0,setup,&irq_ptr,sizeof(void*));
2981 QDIO_PRINT_ERR("allocation of irq_ptr failed!\n");
2985 init_MUTEX(&irq_ptr->setting_up_sema);
2987 /* QDR must be in DMA area since CCW data address is only 32 bit */
2988 irq_ptr->qdr = (struct qdr *) __get_free_page(GFP_KERNEL | GFP_DMA);
2989 if (!(irq_ptr->qdr)) {
2990 free_page((unsigned long) irq_ptr);
2991 QDIO_PRINT_ERR("allocation of irq_ptr->qdr failed!\n");
2994 QDIO_DBF_TEXT0(0,setup,"qdr:");
2995 QDIO_DBF_HEX0(0,setup,&irq_ptr->qdr,sizeof(void*));
2997 if (qdio_alloc_qs(irq_ptr,
2998 init_data->no_input_qs,
2999 init_data->no_output_qs)) {
3000 QDIO_PRINT_ERR("queue allocation failed!\n");
3001 qdio_release_irq_memory(irq_ptr);
3005 init_data->cdev->private->qdio_data = irq_ptr;
3007 qdio_set_state(irq_ptr,QDIO_IRQ_STATE_INACTIVE);
3012 static int qdio_fill_irq(struct qdio_initialize *init_data)
3018 struct qdio_irq *irq_ptr;
3020 irq_ptr = init_data->cdev->private->qdio_data;
3022 memset(irq_ptr,0,((char*)&irq_ptr->qdr)-((char*)irq_ptr));
3024 /* wipes qib.ac, required by ar7063 */
3025 memset(irq_ptr->qdr,0,sizeof(struct qdr));
3027 irq_ptr->int_parm=init_data->int_parm;
3029 irq_ptr->schid = ccw_device_get_subchannel_id(init_data->cdev);
3030 irq_ptr->no_input_qs=init_data->no_input_qs;
3031 irq_ptr->no_output_qs=init_data->no_output_qs;
3033 if (init_data->q_format==QDIO_IQDIO_QFMT) {
3034 irq_ptr->is_iqdio_irq=1;
3035 irq_ptr->is_thinint_irq=1;
3037 irq_ptr->is_iqdio_irq=0;
3038 irq_ptr->is_thinint_irq=hydra_thinints;
3040 sprintf(dbf_text,"is_i_t%1x%1x",
3041 irq_ptr->is_iqdio_irq,irq_ptr->is_thinint_irq);
3042 QDIO_DBF_TEXT2(0,setup,dbf_text);
3044 if (irq_ptr->is_thinint_irq) {
3045 irq_ptr->dev_st_chg_ind = qdio_get_indicator();
3046 QDIO_DBF_HEX1(0,setup,&irq_ptr->dev_st_chg_ind,sizeof(void*));
3047 if (!irq_ptr->dev_st_chg_ind) {
3048 QDIO_PRINT_WARN("no indicator location available " \
3049 "for irq 0.%x.%x\n",
3050 irq_ptr->schid.ssid, irq_ptr->schid.sch_no);
3051 qdio_release_irq_memory(irq_ptr);
3057 irq_ptr->equeue.cmd=DEFAULT_ESTABLISH_QS_CMD;
3058 irq_ptr->equeue.count=DEFAULT_ESTABLISH_QS_COUNT;
3059 irq_ptr->aqueue.cmd=DEFAULT_ACTIVATE_QS_CMD;
3060 irq_ptr->aqueue.count=DEFAULT_ACTIVATE_QS_COUNT;
3062 qdio_fill_qs(irq_ptr, init_data->cdev,
3063 init_data->no_input_qs,
3064 init_data->no_output_qs,
3065 init_data->input_handler,
3066 init_data->output_handler,init_data->int_parm,
3067 init_data->q_format,init_data->flags,
3068 init_data->input_sbal_addr_array,
3069 init_data->output_sbal_addr_array);
3071 if (!try_module_get(THIS_MODULE)) {
3072 QDIO_PRINT_CRIT("try_module_get() failed!\n");
3073 qdio_release_irq_memory(irq_ptr);
3077 qdio_fill_thresholds(irq_ptr,init_data->no_input_qs,
3078 init_data->no_output_qs,
3079 init_data->min_input_threshold,
3080 init_data->max_input_threshold,
3081 init_data->min_output_threshold,
3082 init_data->max_output_threshold);
3085 irq_ptr->qdr->qfmt=init_data->q_format;
3086 irq_ptr->qdr->iqdcnt=init_data->no_input_qs;
3087 irq_ptr->qdr->oqdcnt=init_data->no_output_qs;
3088 irq_ptr->qdr->iqdsz=sizeof(struct qdesfmt0)/4; /* size in words */
3089 irq_ptr->qdr->oqdsz=sizeof(struct qdesfmt0)/4;
3091 irq_ptr->qdr->qiba=(unsigned long)&irq_ptr->qib;
3092 irq_ptr->qdr->qkey=QDIO_STORAGE_KEY;
3095 irq_ptr->is_qebsm = is_passthrough;
3096 if (irq_ptr->is_qebsm)
3097 irq_ptr->qib.rflags |= QIB_RFLAGS_ENABLE_QEBSM;
3099 irq_ptr->qib.qfmt=init_data->q_format;
3100 if (init_data->no_input_qs)
3101 irq_ptr->qib.isliba=(unsigned long)(irq_ptr->input_qs[0]->slib);
3102 if (init_data->no_output_qs)
3103 irq_ptr->qib.osliba=(unsigned long)(irq_ptr->output_qs[0]->slib);
3104 memcpy(irq_ptr->qib.ebcnam,init_data->adapter_name,8);
3106 qdio_set_impl_params(irq_ptr,init_data->qib_param_field_format,
3107 init_data->qib_param_field,
3108 init_data->no_input_qs,
3109 init_data->no_output_qs,
3110 init_data->input_slib_elements,
3111 init_data->output_slib_elements);
3113 /* first input descriptors, then output descriptors */
3114 is_iqdio = (init_data->q_format == QDIO_IQDIO_QFMT) ? 1 : 0;
3115 for (i=0;i<init_data->no_input_qs;i++)
3116 qdio_allocate_fill_input_desc(irq_ptr, i, is_iqdio);
3118 for (i=0;i<init_data->no_output_qs;i++)
3119 qdio_allocate_fill_output_desc(irq_ptr, i,
3120 init_data->no_input_qs,
3123 /* qdr, qib, sls, slsbs, slibs, sbales filled. */
3125 /* get qdio commands */
3126 ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_EQUEUE);
3128 QDIO_DBF_TEXT2(1,setup,"no eq");
3129 QDIO_PRINT_INFO("No equeue CIW found for QDIO commands. "
3130 "Trying to use default.\n");
3132 irq_ptr->equeue = *ciw;
3133 ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_AQUEUE);
3135 QDIO_DBF_TEXT2(1,setup,"no aq");
3136 QDIO_PRINT_INFO("No aqueue CIW found for QDIO commands. "
3137 "Trying to use default.\n");
3139 irq_ptr->aqueue = *ciw;
3141 /* Set new interrupt handler. */
3142 irq_ptr->original_int_handler = init_data->cdev->handler;
3143 init_data->cdev->handler = qdio_handler;
3149 qdio_establish(struct qdio_initialize *init_data)
3151 struct qdio_irq *irq_ptr;
3152 unsigned long saveflags;
3153 int result, result2;
3154 struct ccw_device *cdev;
3157 cdev=init_data->cdev;
3158 irq_ptr = cdev->private->qdio_data;
3162 if (cdev->private->state != DEV_STATE_ONLINE)
3165 down(&irq_ptr->setting_up_sema);
3167 qdio_fill_irq(init_data);
3169 /* the thinint CHSC stuff */
3170 if (irq_ptr->is_thinint_irq) {
3172 result = tiqdio_set_subchannel_ind(irq_ptr,0);
3174 up(&irq_ptr->setting_up_sema);
3175 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
3178 tiqdio_set_delay_target(irq_ptr,TIQDIO_DELAY_TARGET);
3181 sprintf(dbf_text,"qest%4x",cdev->private->schid.sch_no);
3182 QDIO_DBF_TEXT0(0,setup,dbf_text);
3183 QDIO_DBF_TEXT0(0,trace,dbf_text);
3186 irq_ptr->ccw.cmd_code=irq_ptr->equeue.cmd;
3187 irq_ptr->ccw.flags=CCW_FLAG_SLI;
3188 irq_ptr->ccw.count=irq_ptr->equeue.count;
3189 irq_ptr->ccw.cda=QDIO_GET_ADDR(irq_ptr->qdr);
3191 spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags);
3193 ccw_device_set_options_mask(cdev, 0);
3194 result=ccw_device_start_timeout(cdev,&irq_ptr->ccw,
3195 QDIO_DOING_ESTABLISH,0, 0,
3196 QDIO_ESTABLISH_TIMEOUT);
3198 result2=ccw_device_start_timeout(cdev,&irq_ptr->ccw,
3199 QDIO_DOING_ESTABLISH,0,0,
3200 QDIO_ESTABLISH_TIMEOUT);
3201 sprintf(dbf_text,"eq:io%4x",result);
3202 QDIO_DBF_TEXT2(1,setup,dbf_text);
3204 sprintf(dbf_text,"eq:io%4x",result);
3205 QDIO_DBF_TEXT2(1,setup,dbf_text);
3207 QDIO_PRINT_WARN("establish queues on irq 0.%x.%04x: do_IO " \
3208 "returned %i, next try returned %i\n",
3209 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
3213 ccw_device_set_timeout(cdev, 0);
3216 spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags);
3219 up(&irq_ptr->setting_up_sema);
3220 qdio_shutdown(cdev,QDIO_FLAG_CLEANUP_USING_CLEAR);
3224 /* Timeout is cared for already by using ccw_device_start_timeout(). */
3225 wait_event_interruptible(cdev->private->wait_q,
3226 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
3227 irq_ptr->state == QDIO_IRQ_STATE_ERR);
3229 if (irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED)
3232 up(&irq_ptr->setting_up_sema);
3233 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
3237 qdio_get_ssqd_information(irq_ptr);
3238 /* if this gets set once, we're running under VM and can omit SVSes */
3239 if (irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY)
3242 sprintf(dbf_text,"qdioac%2x",irq_ptr->qdioac);
3243 QDIO_DBF_TEXT2(0,setup,dbf_text);
3245 sprintf(dbf_text,"qib ac%2x",irq_ptr->qib.ac);
3246 QDIO_DBF_TEXT2(0,setup,dbf_text);
3248 irq_ptr->hydra_gives_outbound_pcis=
3249 irq_ptr->qib.ac&QIB_AC_OUTBOUND_PCI_SUPPORTED;
3250 irq_ptr->sync_done_on_outb_pcis=
3251 irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS;
3253 qdio_initialize_set_siga_flags_input(irq_ptr);
3254 qdio_initialize_set_siga_flags_output(irq_ptr);
3256 up(&irq_ptr->setting_up_sema);
3263 qdio_activate(struct ccw_device *cdev, int flags)
3265 struct qdio_irq *irq_ptr;
3266 int i,result=0,result2;
3267 unsigned long saveflags;
3268 char dbf_text[20]; /* see qdio_initialize */
3270 irq_ptr = cdev->private->qdio_data;
3274 if (cdev->private->state != DEV_STATE_ONLINE)
3277 down(&irq_ptr->setting_up_sema);
3278 if (irq_ptr->state==QDIO_IRQ_STATE_INACTIVE) {
3283 sprintf(dbf_text,"qact%4x", irq_ptr->schid.sch_no);
3284 QDIO_DBF_TEXT2(0,setup,dbf_text);
3285 QDIO_DBF_TEXT2(0,trace,dbf_text);
3288 irq_ptr->ccw.cmd_code=irq_ptr->aqueue.cmd;
3289 irq_ptr->ccw.flags=CCW_FLAG_SLI;
3290 irq_ptr->ccw.count=irq_ptr->aqueue.count;
3291 irq_ptr->ccw.cda=QDIO_GET_ADDR(0);
3293 spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags);
3295 ccw_device_set_timeout(cdev, 0);
3296 ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
3297 result=ccw_device_start(cdev,&irq_ptr->ccw,QDIO_DOING_ACTIVATE,
3298 0, DOIO_DENY_PREFETCH);
3300 result2=ccw_device_start(cdev,&irq_ptr->ccw,
3301 QDIO_DOING_ACTIVATE,0,0);
3302 sprintf(dbf_text,"aq:io%4x",result);
3303 QDIO_DBF_TEXT2(1,setup,dbf_text);
3305 sprintf(dbf_text,"aq:io%4x",result);
3306 QDIO_DBF_TEXT2(1,setup,dbf_text);
3308 QDIO_PRINT_WARN("activate queues on irq 0.%x.%04x: do_IO " \
3309 "returned %i, next try returned %i\n",
3310 irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
3315 spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags);
3319 for (i=0;i<irq_ptr->no_input_qs;i++) {
3320 if (irq_ptr->is_thinint_irq) {
3322 * that way we know, that, if we will get interrupted
3323 * by tiqdio_inbound_processing, qdio_unmark_q will
3326 qdio_reserve_q(irq_ptr->input_qs[i]);
3327 qdio_mark_tiq(irq_ptr->input_qs[i]);
3328 qdio_release_q(irq_ptr->input_qs[i]);
3332 if (flags&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT) {
3333 for (i=0;i<irq_ptr->no_input_qs;i++) {
3334 irq_ptr->input_qs[i]->is_input_q|=
3335 QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT;
3339 wait_event_interruptible_timeout(cdev->private->wait_q,
3341 QDIO_IRQ_STATE_STOPPED) ||
3343 QDIO_IRQ_STATE_ERR)),
3344 QDIO_ACTIVATE_TIMEOUT);
3346 switch (irq_ptr->state) {
3347 case QDIO_IRQ_STATE_STOPPED:
3348 case QDIO_IRQ_STATE_ERR:
3349 up(&irq_ptr->setting_up_sema);
3350 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
3351 down(&irq_ptr->setting_up_sema);
3355 qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
3359 up(&irq_ptr->setting_up_sema);
3364 /* buffers filled forwards again to make Rick happy */
3366 qdio_do_qdio_fill_input(struct qdio_q *q, unsigned int qidx,
3367 unsigned int count, struct qdio_buffer *buffers)
3369 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
3372 qidx &= (QDIO_MAX_BUFFERS_PER_Q - 1);
3373 if (irq->is_qebsm) {
3375 tmp = set_slsb(q, &qidx, SLSB_CU_INPUT_EMPTY, &count);
3382 set_slsb(q, &qidx, SLSB_CU_INPUT_EMPTY, &count);
3385 qidx = (qidx + 1) & (QDIO_MAX_BUFFERS_PER_Q - 1);
3390 qdio_do_qdio_fill_output(struct qdio_q *q, unsigned int qidx,
3391 unsigned int count, struct qdio_buffer *buffers)
3393 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
3396 qidx &= (QDIO_MAX_BUFFERS_PER_Q - 1);
3397 if (irq->is_qebsm) {
3399 tmp = set_slsb(q, &qidx, SLSB_CU_OUTPUT_PRIMED, &count);
3407 set_slsb(q, &qidx, SLSB_CU_OUTPUT_PRIMED, &count);
3410 qidx = (qidx + 1) & (QDIO_MAX_BUFFERS_PER_Q - 1);
3415 do_qdio_handle_inbound(struct qdio_q *q, unsigned int callflags,
3416 unsigned int qidx, unsigned int count,
3417 struct qdio_buffer *buffers)
3421 /* This is the inbound handling of queues */
3422 used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count;
3424 qdio_do_qdio_fill_input(q,qidx,count,buffers);
3426 if ((used_elements+count==QDIO_MAX_BUFFERS_PER_Q)&&
3427 (callflags&QDIO_FLAG_UNDER_INTERRUPT))
3428 atomic_xchg(&q->polling,0);
3432 if (callflags&QDIO_FLAG_DONT_SIGA)
3437 result=qdio_siga_input(q);
3440 q->error_status_flags|=
3441 QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR;
3442 q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR;
3443 q->siga_error=result;
3451 do_qdio_handle_outbound(struct qdio_q *q, unsigned int callflags,
3452 unsigned int qidx, unsigned int count,
3453 struct qdio_buffer *buffers)
3456 unsigned int cnt, start_buf;
3457 unsigned char state = 0;
3458 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
3460 /* This is the outbound handling of queues */
3461 qdio_do_qdio_fill_output(q,qidx,count,buffers);
3463 used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count;
3465 if (callflags&QDIO_FLAG_DONT_SIGA) {
3466 qdio_perf_stat_inc(&perf_stats.outbound_cnt);
3469 if (callflags & QDIO_FLAG_PCI_OUT)
3473 if (q->is_iqdio_q) {
3474 /* one siga for every sbal */
3476 qdio_kick_outbound_q(q);
3478 __qdio_outbound_processing(q);
3480 /* under VM, we do a SIGA sync unconditionally */
3484 * w/o shadow queues (else branch of
3485 * SYNC_MEMORY :-/ ), we try to
3486 * fast-requeue buffers
3488 if (irq->is_qebsm) {
3490 start_buf = ((qidx+QDIO_MAX_BUFFERS_PER_Q-1) &
3491 (QDIO_MAX_BUFFERS_PER_Q-1));
3492 qdio_do_eqbs(q, &state, &start_buf, &cnt);
3494 state = q->slsb.acc.val[(qidx+QDIO_MAX_BUFFERS_PER_Q-1)
3495 &(QDIO_MAX_BUFFERS_PER_Q-1) ];
3496 if (state != SLSB_CU_OUTPUT_PRIMED) {
3497 qdio_kick_outbound_q(q);
3499 QDIO_DBF_TEXT3(0,trace, "fast-req");
3500 qdio_perf_stat_inc(&perf_stats.fast_reqs);
3504 * only marking the q could take too long,
3505 * the upper layer module could do a lot of
3506 * traffic in that time
3508 __qdio_outbound_processing(q);
3511 qdio_perf_stat_inc(&perf_stats.outbound_cnt);
3514 /* count must be 1 in iqdio */
3516 do_QDIO(struct ccw_device *cdev,unsigned int callflags,
3517 unsigned int queue_number, unsigned int qidx,
3518 unsigned int count,struct qdio_buffer *buffers)
3520 struct qdio_irq *irq_ptr;
3521 #ifdef CONFIG_QDIO_DEBUG
3524 sprintf(dbf_text,"doQD%04x",cdev->private->schid.sch_no);
3525 QDIO_DBF_TEXT3(0,trace,dbf_text);
3526 #endif /* CONFIG_QDIO_DEBUG */
3528 if ( (qidx>QDIO_MAX_BUFFERS_PER_Q) ||
3529 (count>QDIO_MAX_BUFFERS_PER_Q) ||
3530 (queue_number>QDIO_MAX_QUEUES_PER_IRQ) )
3536 irq_ptr = cdev->private->qdio_data;
3540 #ifdef CONFIG_QDIO_DEBUG
3541 if (callflags&QDIO_FLAG_SYNC_INPUT)
3542 QDIO_DBF_HEX3(0,trace,&irq_ptr->input_qs[queue_number],
3545 QDIO_DBF_HEX3(0,trace,&irq_ptr->output_qs[queue_number],
3547 sprintf(dbf_text,"flag%04x",callflags);
3548 QDIO_DBF_TEXT3(0,trace,dbf_text);
3549 sprintf(dbf_text,"qi%02xct%02x",qidx,count);
3550 QDIO_DBF_TEXT3(0,trace,dbf_text);
3551 #endif /* CONFIG_QDIO_DEBUG */
3553 if (irq_ptr->state!=QDIO_IRQ_STATE_ACTIVE)
3556 if (callflags&QDIO_FLAG_SYNC_INPUT)
3557 do_qdio_handle_inbound(irq_ptr->input_qs[queue_number],
3558 callflags, qidx, count, buffers);
3559 else if (callflags&QDIO_FLAG_SYNC_OUTPUT)
3560 do_qdio_handle_outbound(irq_ptr->output_qs[queue_number],
3561 callflags, qidx, count, buffers);
3563 QDIO_DBF_TEXT3(1,trace,"doQD:inv");
3570 qdio_perf_procfile_read(char *buffer, char **buffer_location, off_t offset,
3571 int buffer_length, int *eof, void *data)
3575 /* we are always called with buffer_length=4k, so we all
3576 deliver on the first read */
3580 #define _OUTP_IT(x...) c+=sprintf(buffer+c,x)
3582 _OUTP_IT("Number of tasklet runs (total) : %li\n",
3583 (long)atomic64_read(&perf_stats.tl_runs));
3584 _OUTP_IT("Inbound tasklet runs tried/retried : %li/%li\n",
3585 (long)atomic64_read(&perf_stats.inbound_tl_runs),
3586 (long)atomic64_read(&perf_stats.inbound_tl_runs_resched));
3587 _OUTP_IT("Inbound-thin tasklet runs tried/retried : %li/%li\n",
3588 (long)atomic64_read(&perf_stats.inbound_thin_tl_runs),
3589 (long)atomic64_read(&perf_stats.inbound_thin_tl_runs_resched));
3590 _OUTP_IT("Outbound tasklet runs tried/retried : %li/%li\n",
3591 (long)atomic64_read(&perf_stats.outbound_tl_runs),
3592 (long)atomic64_read(&perf_stats.outbound_tl_runs_resched));
3594 _OUTP_IT("Number of SIGA sync's issued : %li\n",
3595 (long)atomic64_read(&perf_stats.siga_syncs));
3596 _OUTP_IT("Number of SIGA in's issued : %li\n",
3597 (long)atomic64_read(&perf_stats.siga_ins));
3598 _OUTP_IT("Number of SIGA out's issued : %li\n",
3599 (long)atomic64_read(&perf_stats.siga_outs));
3600 _OUTP_IT("Number of PCIs caught : %li\n",
3601 (long)atomic64_read(&perf_stats.pcis));
3602 _OUTP_IT("Number of adapter interrupts caught : %li\n",
3603 (long)atomic64_read(&perf_stats.thinints));
3604 _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %li\n",
3605 (long)atomic64_read(&perf_stats.fast_reqs));
3607 _OUTP_IT("Number of inbound transfers : %li\n",
3608 (long)atomic64_read(&perf_stats.inbound_cnt));
3609 _OUTP_IT("Number of do_QDIOs outbound : %li\n",
3610 (long)atomic64_read(&perf_stats.outbound_cnt));
3611 #else /* CONFIG_64BIT */
3612 _OUTP_IT("Number of tasklet runs (total) : %i\n",
3613 atomic_read(&perf_stats.tl_runs));
3614 _OUTP_IT("Inbound tasklet runs tried/retried : %i/%i\n",
3615 atomic_read(&perf_stats.inbound_tl_runs),
3616 atomic_read(&perf_stats.inbound_tl_runs_resched));
3617 _OUTP_IT("Inbound-thin tasklet runs tried/retried : %i/%i\n",
3618 atomic_read(&perf_stats.inbound_thin_tl_runs),
3619 atomic_read(&perf_stats.inbound_thin_tl_runs_resched));
3620 _OUTP_IT("Outbound tasklet runs tried/retried : %i/%i\n",
3621 atomic_read(&perf_stats.outbound_tl_runs),
3622 atomic_read(&perf_stats.outbound_tl_runs_resched));
3624 _OUTP_IT("Number of SIGA sync's issued : %i\n",
3625 atomic_read(&perf_stats.siga_syncs));
3626 _OUTP_IT("Number of SIGA in's issued : %i\n",
3627 atomic_read(&perf_stats.siga_ins));
3628 _OUTP_IT("Number of SIGA out's issued : %i\n",
3629 atomic_read(&perf_stats.siga_outs));
3630 _OUTP_IT("Number of PCIs caught : %i\n",
3631 atomic_read(&perf_stats.pcis));
3632 _OUTP_IT("Number of adapter interrupts caught : %i\n",
3633 atomic_read(&perf_stats.thinints));
3634 _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %i\n",
3635 atomic_read(&perf_stats.fast_reqs));
3637 _OUTP_IT("Number of inbound transfers : %i\n",
3638 atomic_read(&perf_stats.inbound_cnt));
3639 _OUTP_IT("Number of do_QDIOs outbound : %i\n",
3640 atomic_read(&perf_stats.outbound_cnt));
3641 #endif /* CONFIG_64BIT */
3647 static struct proc_dir_entry *qdio_perf_proc_file;
3650 qdio_add_procfs_entry(void)
3652 proc_perf_file_registration=0;
3653 qdio_perf_proc_file=create_proc_entry(QDIO_PERF,
3654 S_IFREG|0444,&proc_root);
3655 if (qdio_perf_proc_file) {
3656 qdio_perf_proc_file->read_proc=&qdio_perf_procfile_read;
3657 } else proc_perf_file_registration=-1;
3659 if (proc_perf_file_registration)
3660 QDIO_PRINT_WARN("was not able to register perf. " \
3661 "proc-file (%i).\n",
3662 proc_perf_file_registration);
3666 qdio_remove_procfs_entry(void)
3668 if (!proc_perf_file_registration) /* means if it went ok earlier */
3669 remove_proc_entry(QDIO_PERF,&proc_root);
3673 * attributes in sysfs
3674 *****************************************************************************/
3677 qdio_performance_stats_show(struct bus_type *bus, char *buf)
3679 return sprintf(buf, "%i\n", qdio_performance_stats ? 1 : 0);
3683 qdio_performance_stats_store(struct bus_type *bus, const char *buf, size_t count)
3688 i = simple_strtoul(buf, &tmp, 16);
3689 if ((i == 0) || (i == 1)) {
3690 if (i == qdio_performance_stats)
3692 qdio_performance_stats = i;
3694 /* reset perf. stat. info */
3696 atomic64_set(&perf_stats.tl_runs, 0);
3697 atomic64_set(&perf_stats.outbound_tl_runs, 0);
3698 atomic64_set(&perf_stats.inbound_tl_runs, 0);
3699 atomic64_set(&perf_stats.inbound_tl_runs_resched, 0);
3700 atomic64_set(&perf_stats.inbound_thin_tl_runs, 0);
3701 atomic64_set(&perf_stats.inbound_thin_tl_runs_resched,
3703 atomic64_set(&perf_stats.siga_outs, 0);
3704 atomic64_set(&perf_stats.siga_ins, 0);
3705 atomic64_set(&perf_stats.siga_syncs, 0);
3706 atomic64_set(&perf_stats.pcis, 0);
3707 atomic64_set(&perf_stats.thinints, 0);
3708 atomic64_set(&perf_stats.fast_reqs, 0);
3709 atomic64_set(&perf_stats.outbound_cnt, 0);
3710 atomic64_set(&perf_stats.inbound_cnt, 0);
3711 #else /* CONFIG_64BIT */
3712 atomic_set(&perf_stats.tl_runs, 0);
3713 atomic_set(&perf_stats.outbound_tl_runs, 0);
3714 atomic_set(&perf_stats.inbound_tl_runs, 0);
3715 atomic_set(&perf_stats.inbound_tl_runs_resched, 0);
3716 atomic_set(&perf_stats.inbound_thin_tl_runs, 0);
3717 atomic_set(&perf_stats.inbound_thin_tl_runs_resched, 0);
3718 atomic_set(&perf_stats.siga_outs, 0);
3719 atomic_set(&perf_stats.siga_ins, 0);
3720 atomic_set(&perf_stats.siga_syncs, 0);
3721 atomic_set(&perf_stats.pcis, 0);
3722 atomic_set(&perf_stats.thinints, 0);
3723 atomic_set(&perf_stats.fast_reqs, 0);
3724 atomic_set(&perf_stats.outbound_cnt, 0);
3725 atomic_set(&perf_stats.inbound_cnt, 0);
3726 #endif /* CONFIG_64BIT */
3729 QDIO_PRINT_WARN("QDIO performance_stats: write 0 or 1 to this file!\n");
3735 static BUS_ATTR(qdio_performance_stats, 0644, qdio_performance_stats_show,
3736 qdio_performance_stats_store);
3739 tiqdio_register_thinints(void)
3742 register_thinint_result=
3743 s390_register_adapter_interrupt(&tiqdio_thinint_handler);
3744 if (register_thinint_result) {
3745 sprintf(dbf_text,"regthn%x",(register_thinint_result&0xff));
3746 QDIO_DBF_TEXT0(0,setup,dbf_text);
3747 QDIO_PRINT_ERR("failed to register adapter handler " \
3748 "(rc=%i).\nAdapter interrupts might " \
3749 "not work. Continuing.\n",
3750 register_thinint_result);
3755 tiqdio_unregister_thinints(void)
3757 if (!register_thinint_result)
3758 s390_unregister_adapter_interrupt(&tiqdio_thinint_handler);
3762 qdio_get_qdio_memory(void)
3765 indicator_used[0]=1;
3767 for (i=1;i<INDICATORS_PER_CACHELINE;i++)
3768 indicator_used[i]=0;
3769 indicators = kzalloc(sizeof(__u32)*(INDICATORS_PER_CACHELINE),
3777 qdio_release_qdio_memory(void)
3784 qdio_unregister_dbf_views(void)
3787 debug_unregister(qdio_dbf_setup);
3789 debug_unregister(qdio_dbf_sbal);
3791 debug_unregister(qdio_dbf_sense);
3793 debug_unregister(qdio_dbf_trace);
3794 #ifdef CONFIG_QDIO_DEBUG
3795 if (qdio_dbf_slsb_out)
3796 debug_unregister(qdio_dbf_slsb_out);
3797 if (qdio_dbf_slsb_in)
3798 debug_unregister(qdio_dbf_slsb_in);
3799 #endif /* CONFIG_QDIO_DEBUG */
3803 qdio_register_dbf_views(void)
3805 qdio_dbf_setup=debug_register(QDIO_DBF_SETUP_NAME,
3806 QDIO_DBF_SETUP_PAGES,
3807 QDIO_DBF_SETUP_NR_AREAS,
3808 QDIO_DBF_SETUP_LEN);
3809 if (!qdio_dbf_setup)
3811 debug_register_view(qdio_dbf_setup,&debug_hex_ascii_view);
3812 debug_set_level(qdio_dbf_setup,QDIO_DBF_SETUP_LEVEL);
3814 qdio_dbf_sbal=debug_register(QDIO_DBF_SBAL_NAME,
3815 QDIO_DBF_SBAL_PAGES,
3816 QDIO_DBF_SBAL_NR_AREAS,
3821 debug_register_view(qdio_dbf_sbal,&debug_hex_ascii_view);
3822 debug_set_level(qdio_dbf_sbal,QDIO_DBF_SBAL_LEVEL);
3824 qdio_dbf_sense=debug_register(QDIO_DBF_SENSE_NAME,
3825 QDIO_DBF_SENSE_PAGES,
3826 QDIO_DBF_SENSE_NR_AREAS,
3827 QDIO_DBF_SENSE_LEN);
3828 if (!qdio_dbf_sense)
3831 debug_register_view(qdio_dbf_sense,&debug_hex_ascii_view);
3832 debug_set_level(qdio_dbf_sense,QDIO_DBF_SENSE_LEVEL);
3834 qdio_dbf_trace=debug_register(QDIO_DBF_TRACE_NAME,
3835 QDIO_DBF_TRACE_PAGES,
3836 QDIO_DBF_TRACE_NR_AREAS,
3837 QDIO_DBF_TRACE_LEN);
3838 if (!qdio_dbf_trace)
3841 debug_register_view(qdio_dbf_trace,&debug_hex_ascii_view);
3842 debug_set_level(qdio_dbf_trace,QDIO_DBF_TRACE_LEVEL);
3844 #ifdef CONFIG_QDIO_DEBUG
3845 qdio_dbf_slsb_out=debug_register(QDIO_DBF_SLSB_OUT_NAME,
3846 QDIO_DBF_SLSB_OUT_PAGES,
3847 QDIO_DBF_SLSB_OUT_NR_AREAS,
3848 QDIO_DBF_SLSB_OUT_LEN);
3849 if (!qdio_dbf_slsb_out)
3851 debug_register_view(qdio_dbf_slsb_out,&debug_hex_ascii_view);
3852 debug_set_level(qdio_dbf_slsb_out,QDIO_DBF_SLSB_OUT_LEVEL);
3854 qdio_dbf_slsb_in=debug_register(QDIO_DBF_SLSB_IN_NAME,
3855 QDIO_DBF_SLSB_IN_PAGES,
3856 QDIO_DBF_SLSB_IN_NR_AREAS,
3857 QDIO_DBF_SLSB_IN_LEN);
3858 if (!qdio_dbf_slsb_in)
3860 debug_register_view(qdio_dbf_slsb_in,&debug_hex_ascii_view);
3861 debug_set_level(qdio_dbf_slsb_in,QDIO_DBF_SLSB_IN_LEVEL);
3862 #endif /* CONFIG_QDIO_DEBUG */
3865 QDIO_PRINT_ERR("not enough memory for dbf.\n");
3866 qdio_unregister_dbf_views();
3870 static void *qdio_mempool_alloc(gfp_t gfp_mask, void *size)
3872 return (void *) get_zeroed_page(gfp_mask|GFP_DMA);
3875 static void qdio_mempool_free(void *element, void *size)
3877 free_page((unsigned long) element);
3886 printk("qdio: loading %s\n",version);
3888 res=qdio_get_qdio_memory();
3892 qdio_q_cache = kmem_cache_create("qdio_q", sizeof(struct qdio_q),
3894 if (!qdio_q_cache) {
3895 qdio_release_qdio_memory();
3899 res = qdio_register_dbf_views();
3901 kmem_cache_destroy(qdio_q_cache);
3902 qdio_release_qdio_memory();
3906 QDIO_DBF_TEXT0(0,setup,"initQDIO");
3907 res = bus_create_file(&ccw_bus_type, &bus_attr_qdio_performance_stats);
3909 memset((void*)&perf_stats,0,sizeof(perf_stats));
3910 QDIO_DBF_TEXT0(0,setup,"perfstat");
3912 QDIO_DBF_HEX0(0,setup,&ptr,sizeof(void*));
3914 qdio_add_procfs_entry();
3916 qdio_mempool_scssc = mempool_create(QDIO_MEMPOOL_SCSSC_ELEMENTS,
3918 qdio_mempool_free, NULL);
3920 if (tiqdio_check_chsc_availability())
3921 QDIO_PRINT_ERR("Not all CHSCs supported. Continuing.\n");
3923 tiqdio_register_thinints();
3931 tiqdio_unregister_thinints();
3932 qdio_remove_procfs_entry();
3933 qdio_release_qdio_memory();
3934 qdio_unregister_dbf_views();
3935 mempool_destroy(qdio_mempool_scssc);
3936 kmem_cache_destroy(qdio_q_cache);
3937 bus_remove_file(&ccw_bus_type, &bus_attr_qdio_performance_stats);
3938 printk("qdio: %s: module removed\n",version);
3941 module_init(init_QDIO);
3942 module_exit(cleanup_QDIO);
3944 EXPORT_SYMBOL(qdio_allocate);
3945 EXPORT_SYMBOL(qdio_establish);
3946 EXPORT_SYMBOL(qdio_initialize);
3947 EXPORT_SYMBOL(qdio_activate);
3948 EXPORT_SYMBOL(do_QDIO);
3949 EXPORT_SYMBOL(qdio_shutdown);
3950 EXPORT_SYMBOL(qdio_free);
3951 EXPORT_SYMBOL(qdio_cleanup);
3952 EXPORT_SYMBOL(qdio_synchronize);